开发者

How to add observers to an NSManagedObject?

开发者 https://www.devze.com 2023-02-25 15:31 出处:网络
What is the preferred approach to registering observers on an NSManagedObject (since Core Data \"\'owns\' the lifecycle\" of managed objects)?

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).

0

精彩评论

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