views:

59

answers:

1

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 inserted 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?

+2  A: 

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

Louis Gerbarg