ModelAdapter
An object conforming to ModelAdapter
will track the local model, provide changes to upload to CloudKit and import downloaded changes.
@objc public protocol ModelAdapter: class
#
Inheritanceclass
#
Requirements#
hasChangesWhether the model has any changes
var hasChanges: Bool
#
prepareToImport()Tells the model adapter that an import operation will begin
func prepareToImport()
#
saveChanges(in:β)Apply changes in the provided record to the local model objects and save the records.
func saveChanges(in records: [CKRecord])
#
Parameters- records: Array of
CKRecord
that were obtained from CloudKit.
#
deleteRecords(with:β)Delete the local model objects corresponding to the given record IDs.
func deleteRecords(with recordIDs: [CKRecord.ID])
#
Parameters- recordIDs: Array of identifiers of records that were deleted on CloudKit.
#
persistImportedChanges(completion:β)Tells the model adapter to persist all downloaded changes in the current import operation.
func persistImportedChanges(completion: @escaping (Error?)->())
#
Parameters- completion: Block to be called after changes have been persisted.
#
recordsToUpload(limit:β)Provides an array of up to limit
records with changes that need to be uploaded to CloudKit.
func recordsToUpload(limit: Int) -> [CKRecord]
#
Parameters- limit: Maximum number of records that should be provided.
#
ReturnsArray of CKRecord
.
#
didUpload(savedRecords:β)Tells the model adapter that these records were uploaded successfully to CloudKit.
func didUpload(savedRecords: [CKRecord])
#
Parameters- savedRecords: Records that were saved.
#
recordIDsMarkedForDeletion(limit:β)Provides an array of record IDs to be deleted on CloudKit, for model objects that were deleted locally.
func recordIDsMarkedForDeletion(limit: Int) -> [CKRecord.ID]
#
Parameters- limit: Maximum number of records that should be provided.
#
ReturnsArray of CKRecordID
.
#
didDelete(recordIDs:β)Tells the model adapter that these record identifiers were deleted successfully from CloudKit.
func didDelete(recordIDs: [CKRecord.ID])
#
Parameters- recordIDs: Record IDs that were deleted on CloudKit.
#
hasRecordID(_:β)Asks the model adapter whether it has a local object for the given record identifier.
func hasRecordID(_ recordID: CKRecord.ID) -> Bool
#
Parameters- recordID: Record identifier.
#
ReturnsWhether there is a corresponding object for this identifier.
#
didFinishImport(with:β)Tells the model adapter that the current import operation finished.
func didFinishImport(with error: Error?)
#
Parameters- error: Optional error, if any error happened.
#
recordZoneIDRecord zone ID managed by this adapter
var recordZoneID: CKRecordZone.ID
#
serverChangeTokenLatest CKServerChangeToken
stored by this adapter, or nil
if one does not exist.
var serverChangeToken: CKServerChangeToken?
#
saveToken(_:β)Save given token for future use by this adapter.
func saveToken(_ token: CKServerChangeToken?)
#
Parameters- token:
CKServerChangeToken
#
deleteChangeTracking()func deleteChangeTracking()
- Deletes all tracking information and detaches from local model.
- This adapter should not be used after calling this method, create a new adapter if you wish to synchronize
- the same model again.
#
mergePolicyMerge policy in case of conflicts. Default is server
.
var mergePolicy: MergePolicy
#
record(for:β)Returns corresponding CKRecord
for the given model object.
func record(for object: AnyObject) -> CKRecord?
#
Parameters- object: Model object.
#
share(for:β)Returns CKShare for the given model object, if one exists.
@available(iOS 10.0, OSX 10.12, *) func share(for object: AnyObject) -> CKShare?
#
Parameters- object: Model object.
#
save(share:βfor:β)Store CKShare for given model object.
@available(iOS 10.0, OSX 10.12, *) func save(share: CKShare, for object: AnyObject)
#
Parameters- share:
CKShare
object to save. - object: Model object.
#
deleteShare(for:β)Delete existing CKShare
for given model object.
@available(iOS 10.0, OSX 10.12, *) func deleteShare(for object: AnyObject)
#
Parameters- object: Model object.
#
shareForRecordZone()@available(iOS 15.0, OSX 12, *) func shareForRecordZone() -> CKShare?
- Returns: CKShare for the adapter's record zone, if one exists.
#
saveShareForRecordZone(share:β)Store CKShare for the record zone.
@available(iOS 15.0, OSX 12, *) func saveShareForRecordZone(share: CKShare)
#
Parameters- share:
CKShare
object to save.
#
deleteShareForRecordZone()Delete existing CKShare
for adapter's record zone.
@available(iOS 15.0, OSX 12, *) func deleteShareForRecordZone()
#
recordsToUpdateParentRelationshipsForRoot(_:β)Returns a list of records for the given object and any parent records, recursively.
func recordsToUpdateParentRelationshipsForRoot(_ object: AnyObject) -> [CKRecord]
#
Parameters- object: Model object.
#
ReturnsArray of CKRecord