diff --git a/Source/Classes/CloudCore.swift b/Source/Classes/CloudCore.swift index a35a6c56..64aa392f 100644 --- a/Source/Classes/CloudCore.swift +++ b/Source/Classes/CloudCore.swift @@ -83,8 +83,9 @@ open class CloudCore { /// Enable CloudKit and Core Data synchronization /// /// - Parameters: - /// - container: `NSPersistentContainer` that will be used to save data - public static func enable(persistentContainer container: NSPersistentContainer) { + /// - container: `NSPersistentContainer` that will be used to save data + /// - withPull: `Bool` to specify if Pull shoul dbe perfromed or not on enable + public static func enable(persistentContainer container: NSPersistentContainer, withPull: Bool) { // Listen for local changes let observer = CoreDataObserver(container: container) observer.delegate = self.delegate @@ -98,6 +99,10 @@ open class CloudCore { queue.addOperation(subscribeOperation) #endif + if !withPull { + return + } + // Fetch updated data (e.g. push notifications weren't received) let updateFromCloudOperation = PullOperation(persistentContainer: container) updateFromCloudOperation.errorBlock = { @@ -110,6 +115,10 @@ open class CloudCore { queue.addOperation(updateFromCloudOperation) } + + public static func enable(persistentContainer container: NSPersistentContainer) { + self.enable(persistentContainer: container, withPull: true) + } /// Disables synchronization (push notifications won't be sent also) public static func disable() { diff --git a/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift b/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift index 10001414..f58552ee 100644 --- a/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift +++ b/Source/Classes/Pull/SubOperations/RecordToCoreDataOperation.swift @@ -52,6 +52,10 @@ public class RecordToCoreDataOperation: AsynchronousOperation { private func setManagedObject(in context: NSManagedObjectContext) throws { let entityName = record.recordType + /// cloudkit.share records are generated by CloudKit when records are shared. + /// No need to get them in Core Data entities. + if entityName == "cloudkit.share" {return} + guard let entity = NSEntityDescription.entity(forEntityName: entityName, in: context) else { throw CloudCoreError.coreData("Unable to find entity specified in CKRecord: " + entityName) } diff --git a/Source/Model/CloudCoreConfig.swift b/Source/Model/CloudCoreConfig.swift index 3e96b043..034afccf 100644 --- a/Source/Model/CloudCoreConfig.swift +++ b/Source/Model/CloudCoreConfig.swift @@ -26,6 +26,8 @@ import CloudKit public struct CloudCoreConfig { // MARK: CloudKit + + public init() {} /// The CKContainer to store CoreData. Set this to a custom container to /// support sharing data between multiple apps in an App Group (e.g. iOS and macOS).