Swiftpack.co - msigsbey/CKCodable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by msigsbey.
msigsbey/CKCodable v0.0.1
A library for encoding and decoding CKRecords
⭐️ 2
🕓 2 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/msigsbey/CKCodable.git", from: "v0.0.1")


A library for encoding and decoding CKRecords

GitHub tag (latest by date) Swift Package Manager Swift5 Platform GitHub repo size

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:

Step 1 - Import CKCodable

import CKCodable

Step 2 - Implement CKCodable

public struct SomeType: CKCodable {
    var systemFields: Data?
    Note: Optionl override for default record provider.
    var newRecordProvider: CKRecordProvider {
                recordType: String(describing: Self.self), // RecordType using self
                recordID: CKRecord.ID(
                    recordName: UUID().uuidString, // RecordName as random UUID
                    zoneID: .default // Default CKRecordZone

Step 3 - Add your own values from the Supported Data Types

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

Step 4 - Encode and Decode your types

// 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.


Stars: 2
Last commit: 5 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

2 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics