New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel sync process #540
Comments
Hi! Sync uses (NS)Operations, so if you make an OperationQueue and add sync to it then you can cancel it at any point. |
I'll see if I can add some docs later, but here are you see Sync is a subclass of Operation: Line 17 in b51324e
|
Hi Thanks for help let sync = Sync(changes: changes, inEntityNamed: entityName, dataStack: dataStack, operations: syncOptions) queue.addOperations([sync], waitUntilFinished: false)` Only one thing i missing: Best Zoltan |
Hi Zoltan, You're right, error handling wasn't 100% finished, I'm using I think we might need to introduce a Best |
Hi Elvis one approach can be to add public error variable to Sync class: public var error: NSError? and than: func perform(using context: NSManagedObjectContext) {
do {
try Sync.changes(self.changes, inEntityNamed: self.entityName, predicate: self.predicate, parent: self.parent, parentRelationship: self.parentRelationship, inContext: context, operations: self.filterOperations, shouldContinueBlock: { () -> Bool in
return !self.isCancelled
}, objectJSONBlock: { objectJSON -> [String: Any] in
return self.delegate?.sync(self, willInsert: objectJSON, in: self.entityName, parent: self.parent) ?? objectJSON
})
} catch let error as NSError {
print("Failed syncing changes \(error)")
self.error = error
}
self.updateExecuting(false)
self.updateFinished(true)
} in the code user can check for e.g. error like this: let sync = Sync(changes: changes, inEntityNamed: entityName, dataStack: dataStack, operations: syncOptions)
sync.completionBlock = { [unowned sync] in
if let completion = completion {
completion(sync.error)
}
} but maybe there is better aproach Best Zoltan |
Thanks for your support in this library. It has been a while since I used CoreData in any of my projects and it's hard for me to maintain this library. If you have been part of the Sync contributors group and want to take ownership of the library let me know to elvisnunez@me.com. For now, I'll be archiving this library. |
Hi Guys
Is there a way to cancel a syncing process? I haven't found it in the documentation.
I'm syncing a downloaded json to core data with DataStack. it can take a while, when json has lets say 50 entities.
e.g when user logs out from the app I'm deleting his data from database, but when he logs out during sync and the sync is finished after he logged out, then the deleted data is unfortunatly back in the database.
So anyway I want to cancel syncing when user logs out.
Thanks for help
Zoltan
The text was updated successfully, but these errors were encountered: