I see in "How (and when) do I use iCloud's encodeSystemFields method on CKRecord?" how to use NSKeyedArchiver to cache the salient fields of CKRecord. Is there a way to use JSONEncoder with encodeSystemFields
? My other cache data is saved as JSON so I'd like encodeSystemFields
to fit with that.
Unfortunately Data
is not allowed in valid JSON despite being Codable, and fails the test JSONSerialization.isValidJSONObject
, so I can't just jam the output of NSKeyedArchiver
into my JSON serialization.
let d = Data()
d is Codable // true
// ...encodeSystemFields...
JSONSerialization.isValidJSONObject([d]) // false
let listofd = [d]
JSONSerialization.isValidJSONObject(listofd) // false
let dictofd = ["test":d]
JSONSerialization.isValidJSONObject(dictofd) // false
It doesn't matter if d
is Data
or NSMutableData
. I get the same results.