Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active May 16, 2016 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3lvis/fca1fa6449f554ed6ff33c0e00b136b7 to your computer and use it in GitHub Desktop.
Save 3lvis/fca1fa6449f554ed6ff33c0e00b136b7 to your computer and use it in GitHub Desktop.
let remoteItems = localPrimaryKey
let localRelationship = self.valueForKey(relationship.name)
let localItems = localRelationship?.valueForKey(entity.sync_localPrimaryKey()) as? NSArray ?? NSArray()
let intersection = NSMutableSet(array: remoteItems as [AnyObject])
intersection.intersectSet(Set(arrayLiteral: localItems))
let updatedItems = intersection.allObjects
let deletedItems = localItems.mutableCopy()
deletedItems.removeObjectsInArray(remoteItems as [AnyObject])
let insertedItems = remoteItems.mutableCopy()
insertedItems.removeObjectsInArray(localItems as [AnyObject])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment