开发者

Am I permitted to change the object graph in NSManagedObjectContextObjectsDidChangeNotification?

开发者 https://www.devze.com 2022-12-10 11:54 出处:网络
I\'d like to know when an object has been inserted into my Core Data MOC and when it has, add it to another object with a relationship.

I'd like to know when an object has been inserted into my Core Data MOC and when it has, add it to another object with a relationship.

So I watch the NSManagedObjectContextObjectsDidChangeNotification notifications find all the objects of the correct class in the set of i开发者_如何学Gonserted objects and make the connection using addObject so that the KVO is handled correctly. It appears to work just fine.

Is this legal inside NSManagedObjectContextObjectsDidChangeNotification?


That is perfectly legal, you just need to be careful when you do things like this that you don't cause infinite recursion (by, for instance, inserting an object that cause a notification the causes you to add an object, etc).

0

精彩评论

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