How to add observers to an NSManagedObject?
What is the preferred approach to registering observers on an NSManagedObject
(since Core Data "'owns' the lifecycle" of managed objects)?
Am I correct that the way to do this is to listen for NSManagedO开发者_StackOverflow中文版bjectContextObjectsDidChange-Notification
and call addObserver:...
for NSInsertedObjectsKey
and removeObserver:...
for NSDeletedObjectsKey
?
In order to observe MOs throughout their lifecycles, add observers when they come into existence, with awakeFromInsert
and awakeFromFetch
.
Yeah, you're correct. Observing the MOs directly will lead to trouble, for reasons you have already posted in your question (within the parentheses).
精彩评论