Skip to main content

CoreDataAdapter

Implementation of ModelAdapter for Core Data models.

@objc public class CoreDataAdapter: NSObject, ModelAdapter 

Inheritance#

ModelAdapter, NSObject

Initializers#

init(persistenceStack:targetContext:recordZoneID:delegate:)#

Initialize a new CoreDataAdapter.

@objc public init(persistenceStack: CoreDataStack, targetContext: NSManagedObjectContext, recordZoneID: CKRecordZone.ID, delegate: CoreDataAdapterDelegate) 

Parameters#

  • persistenceStack: CoreDataStack for internal state.
  • targetContext: NSManagedObjectContext to keep in sync with CloudKit.
  • recordZoneID: CKRecordZone.ID of the record zone that will be used on CloudKit.
  • delegate: CoreDataAdapterDelegate to trigger saves in the target context.

Properties#

serverChangeToken#

public var serverChangeToken: CKServerChangeToken? 

targetContext#

The target NSManagedObjectContext that will be tracked. (read-only)

@objc public let targetContext: NSManagedObjectContext

delegate#

@objc public let delegate: CoreDataAdapterDelegate

recordProcessingDelegate#

@objc public weak var recordProcessingDelegate: CoreDataAdapterRecordProcessing?

conflictDelegate#

@objc public var conflictDelegate: CoreDataAdapterConflictResolutionDelegate?

recordZoneID#

Record Zone that is kept in sync with this adapter's NSManagedObjectContext.

@objc public let recordZoneID: CKRecordZone.ID

mergePolicy#

Merge policy in case of conflicts. Default value is server.

@objc public var mergePolicy: MergePolicy = .server

forceDataTypeInsteadOfAsset#

By default objects with Data values will be uploaded as a CKRecord with a CKAsset field. Set this property to true to force using Data in the record instead.

@objc public var forceDataTypeInsteadOfAsset = false

hasChanges#

Whether the target context has made any changes that have not been synced to CloudKit yet.

public var hasChanges = false

timestampKey#

Records generated by this adapter will use this key to set a change timestamp.

public static let timestampKey = "QSCloudKitTimestampKey"

Methods#

prepareToImport()#

public func prepareToImport() 

saveChanges(in:)#

public func saveChanges(in records: [CKRecord]) 

deleteRecords(with:)#

public func deleteRecords(with recordIDs: [CKRecord.ID]) 

persistImportedChanges(completion:)#

public func persistImportedChanges(completion: @escaping (Error?)->()) 

recordsToUpload(limit:)#

public func recordsToUpload(limit: Int) -> [CKRecord] 

didUpload(savedRecords:)#

public func didUpload(savedRecords: [CKRecord]) 

recordIDsMarkedForDeletion(limit:)#

public func recordIDsMarkedForDeletion(limit: Int) -> [CKRecord.ID] 

didDelete(recordIDs:)#

public func didDelete(recordIDs: [CKRecord.ID]) 

hasRecordID(_:)#

public func hasRecordID(_ recordID: CKRecord.ID) -> Bool 

didFinishImport(with:)#

public func didFinishImport(with error: Error?) 

saveToken(_:)#

public func saveToken(_ token: CKServerChangeToken?) 

deleteChangeTracking()#

public func deleteChangeTracking() 

record(for:)#

public func record(for object: AnyObject) -> CKRecord? 

share(for:)#

@available(iOS 10.0, OSX 10.12, *)    public func share(for object: AnyObject) -> CKShare? 

save(share:for:)#

@available(iOS 10.0, OSX 10.12, *)    public func save(share: CKShare, for object: AnyObject) 

deleteShare(for:)#

@available(iOS 10.0, OSX 10.12, *)    public func deleteShare(for object: AnyObject) 

shareForRecordZone()#

@available(iOS 15.0, OSX 12, *)    public func shareForRecordZone() -> CKShare? 

saveShareForRecordZone(share:)#

Store CKShare for the record zone.

@available(iOS 15.0, OSX 12, *)    public 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, *)    public func deleteShareForRecordZone() 

recordsToUpdateParentRelationshipsForRoot(_:)#

public func recordsToUpdateParentRelationshipsForRoot(_ object: AnyObject) -> [CKRecord]