开发者

NSFetchedResultsController: how does it know which objects to call its delegate for?

Anybody care to speculate about the inte开发者_如何学Gornal workings of NSFetchedResultsController?

Specifically: how does it know which objects to call its delegate methods for? If I were to implement NSFRC, I'd do it this way: 1) register for all the notifications from the managed context, and 2) when I get a notification, check the type of the object against the type of the entity of the fetch request in the NSFRC, and check whether the predicate (if it exists) in the NSFRC returns true for that object, and if both are true, then call the delegate's ...didChangeObject... method.

Seems clunky though somehow, especially with that type-check (use isKindOf?). Just asking because I need to implement something similar in that respect to NSFRC.


The managed object context broadcast a series of notifications and the user info dictionary of the notification contains the managed objects that were inserted, deleted, or updated.

E.g.

NSManagedObjectContextObjectsDidChangeNotification

Posted when values of properties of objects contained in a managed object context are changed. The notification is posted during processPendingChanges, after the changes have been processed, but before it is safe to call save: again (if you try, you will generate an infinite loop).

The notification object is the managed object context. The userInfo dictionary contains the following keys: NSInsertedObjectsKey, NSUpdatedObjectsKey, and NSDeletedObjectsKey.

The FRC then just checks the entity of the returned object across it's own entity and if it matches sends its delegate messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜