Created
October 27, 2017 18:19
-
-
Save hhanesand/50eb99d56c5dc4694b84a774e06a2c59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
- (RLMNotificationToken *)startCreatingTasksForOperationType:(MUSOperationType)type { | |
RLMResults *results = self.resultsBlock(type); | |
if (!results) { | |
return nil; | |
} | |
return [results addNotificationBlock:^(RLMResults * _Nullable results, RLMCollectionChange * _Nullable change, NSError * _Nullable error) { | |
if (error) { | |
NSLog(@"%@ results error : %@", self, error); | |
return; | |
} | |
if (!change) { | |
[self processObjects:(id<MUSSubscriptable>)results forOperationType:type]; | |
} else { | |
// Realm converts moves to deletion and insertion pairs : https://github.com/realm/realm-cocoa/issues/3571 | |
// We only want added or modified objects, so we ignore any moved or deleted objects. (moved == delete/insert pair) | |
NSMutableSet<NSNumber *> *insertionsWithoutMoves = [NSMutableSet setWithArray:change.insertions]; | |
[insertionsWithoutMoves minusSet:[NSSet setWithArray:change.deletions]]; | |
NSSet *addedOrModified = [insertionsWithoutMoves setByAddingObjectsFromArray:change.modifications]; | |
id<MUSSubscriptable> addedOrModifiedObjects = (id<MUSSubscriptable>)[results mus_objectsAtIndexes:addedOrModified.allObjects]; | |
[self processObjects:addedOrModifiedObjects forOperationType:type]; | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment