Latest 1.0.1
Homepage https://github.com/ovrchk/CKSyncer
License MIT
Platforms ios 10.0
Authors

CI Status
Version
License
Platform

Example

  let container = CKContainer.default()

  let changeTokenProvider = UserDefaultsServerChangeTokenProvider()

  let syncer = CKSyncer(container: container,
                        database: container.privateCloudDatabase,
                        recordZone: CKRecordZone.default(),
                        tokenProvider: changeTokenProvider)

  //getting CloudKit account status

  syncer.getCloudKitStatus { (status, error) in
      if let available = status, available == true {
          //CloudKit is avaiable and can be used for data sync
      }
  }

  //fetching remote changes using CKServerChangeToken managed by changeTokenProvider

  syncer.applyRemoteChanges({ (createdOrUpdatedRecords, deletedRecordsIdentifiers) -> Bool in

      createdOrUpdatedRecords.forEach({

          let record:CKRecord = $0

          //TODO: create or update local record using given CKRecord
      })

      deletedRecordsIdentifiers.forEach({
          let recordType = $0.0
          let remoteRecordID = $0.1

          //TODO: delete record matching remote type and record ID
      })

      //return true if you're sure that all data persisted
      //in only that case, change token will be saved by token provider to use on next fetch
      return true
  }) { (_) in
      //handle error
  }

  //Applying local changes to CloudKit database

  var localChanges = LocalChanges()

  //TODO: update local changes object with created, updated and deleted objects
  //        localChanges.createdObjects = ...
  //        localChanges.updatedObjects = ...
  //        localChanges.deletedObjects = ...

  syncer.applyLocalChanges(localChanges) { (savedRecords, deletedRecordIDs, error) in

      savedRecords?.forEach({

          let savedRecord:CKRecord = $0

          //TODO: mark matching local record as synced
      })

      deletedRecordIDs?.forEach({

          let deletedRecordID:CKRecordID = $0

          //TODO: delete matching local record
      })
  }

Requirements

Installation

CKSyncer is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'CKSyncer'

Author

Dmitry, [email protected]

License

CKSyncer is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "CKSyncer",
    "version": "1.0.1",
    "summary": "Tiny CloudKit syncing engine",
    "description": "Tiny CloudKit syncing engine which",
    "homepage": "https://github.com/ovrchk/CKSyncer",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dmitry": "[email protected]"
    },
    "source": {
        "git": "https://github.com/ovrchk/CKSyncer.git",
        "tag": "1.0.1"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "CKSyncer/Source/**/*",
    "swift_version": "4.0"
}

Pin It on Pinterest

Share This