Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SixBe/ad2412978faa5b980b418f396f91aef9 to your computer and use it in GitHub Desktop.
Save SixBe/ad2412978faa5b980b418f396f91aef9 to your computer and use it in GitHub Desktop.
extension NSFetchedResultsController {
private func processChangesWithWillAccessValueForKey(notification: NSNotification) {
guard let _ = self.fetchRequest.predicate, _ = self.fetchRequest.entity else {
return
}
var matchingObjectIDs = self.insertedOrUpdatedObjectIDsMatchingFetchRequestInNotification(notification)
self.managedObjectContext.performBlock({
let registeredObjectIDs = self.managedObjectContext.registeredObjects.map{$0.objectID}
matchingObjectIDs.subtractInPlace(registeredObjectIDs)
for matchingObjectID in matchingObjectIDs {
guard let object = try? self.managedObjectContext.existingObjectWithID(matchingObjectID) else {
continue
}
object.willAccessValueForKey(nil)
}
if !matchingObjectIDs.isEmpty {
self.managedObjectContext.mergeChangesFromContextDidSaveNotification(notification)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment