What are the most 'modern' Swift ways to store objects like CMTime and CMTimeRange in plist? I have tried the following approaches. The dictionary object gets stored in plist.
dictionary["timeRange"] = NSValue(timeRange: timeRange)
and also,
dictionary["timeRange"] = CMTimeRangeCopyAsDictionary(timeRange, allocator: kCFAllocatorDefault)
The problem with the first approach as someone pointed out is NSValue is more of Objective-C kind of stuff and it needs to be archived before it can be stored in a plist. The second approach is a dictionary based approach where timeRange is stored as CFDictionary but is compatible with plist without any need to archive. But it is CFDictionary that is even farther away from Swift!
So what's a modern way of making CMTimeRange property list serialisable?
Use
PropertyListEncoder
/PropertyListDecoder
with aCodable
model type.CMTime
andCMTimeRange
are notCodable
conformant by default, so you need to add the conformance yourself.