A library for encoding and decoding CKRecords
CKCodable is a type built to streamline the data pipeline between a Codable object and a CloudKit CKRecord.
CKCodable is available via Swift Package Manager
Conform to CKCodable
to enable encoding and decoding with the CKRecordEncoder
and CKRecordDecoder
respectively. It can be integrated within your system like this:
import CKCodable
public struct SomeType: CKCodable {
var systemFields: Data?
/*
Note: Optionl override for default record provider.
var newRecordProvider: CKRecordProvider {
{
CKRecord(
recordType: String(describing: Self.self), // RecordType using self
recordID: CKRecord.ID(
recordName: UUID().uuidString, // RecordName as random UUID
zoneID: .default // Default CKRecordZone
)
)
}
}
*/
}
public struct SomeType: CKCodable {
var systemFields: Data?
/// A `Bool` flag.
let flag: Bool
/// A `String` name.
let name: String
/// A creation `Date`.
let createdAt: Date
/// A `URL` link.
let link: URL
/// A file `URL`.
let file: URL
}
// Encode to CKRecord
let obj: SomeType = // input Sometype
let record: CKRecord = try CKRecordEncoder().encode(obj)
// Decode to SomeType
let record: CKRecord = // input CKRecord
let objc: SomeType = try CKRecordDecoder().decode(from: record)
CKCodable is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 3 |
Last commit: 23 weeks ago |
Full Changelog: https://github.com/msigsbey/CKCodable/compare/v0.0.1...v0.0.2
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics