Codable support for Encoding and Decoding to CKRecord
s for storage in CloudKit, with some caveats:
CKRecord
Array
, Set
, etc...) can only store homogeneous primitive types.Dictionary
because the dictionary keys are used to build keys within the CKRecord, so any keys you use must be part of your schema.Identifiable where ID: CustomStringConvertible
from which the CKRecord.ID will be derived.In this example, the CKRecord will have keys: "id", "name", "sub_name", "sub_someValue"
struct Element: Codable, Identifiable {
var id = UUID
var name = "My Name"
var sub: SubElement()
}
struct SubElement: Codable {
var name = "Other Name"
var someValue = 42
}
let value = Element()
// Encode
let encoder = CloudRecordEncoder()
let record = try encoder.encode(value)
// Decode
let decoder = CloudRecordDecoder()
let decodedValue = try decoder.decode(Element.self, from: record)
link |
Stars: 2 |
Last commit: 3 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics