Last active
March 30, 2017 19:46
-
-
Save SixBe/ad2412978faa5b980b418f396f91aef9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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