Skip to content

Sync — 1.5.0

Compare
Choose a tag to compare
@3lvis 3lvis released this 08 Feb 10:36
· 817 commits to master since this release
  • Added an additional Sync method.
class func changes(changes: [[String : AnyObject]], inEntityNamed entityName: String, predicate: NSPredicate?, parent: NSManagedObject?, inContext context: NSManagedObjectContext, dataStack: DATAStack, completion: ((error: NSError?) -> Void)?)

This method is useful to control even more parts of Sync, for example if you want to use a special context that triggers notifications when an object gets changed.

For example:

self.dataStack.performInNewBackgroundContext { backgroundContext in
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeNotification:", name: NSManagedObjectContextObjectsDidChangeNotification, object: backgroundContext)

    Sync.changes(json["data"] as! Array, inEntityNamed: "Data", predicate: nil, parent: nil, inContext: backgroundContext, dataStack: self.dataStack, completion: { error in
        NSNotificationCenter.defaultCenter().removeObserver(self, name: NSManagedObjectContextObjectsDidChangeNotification, object: nil)
        completion(error)
    })
}