Clean way to save observers on CoreData objects?
I am wondering if it would be possible to save and restore the observer of keyPaths of CoreData Entities.
Example: I have 300 Employees in my managedObjectContext. When I insert them the first time i call addObserver: .. for all of them, so that some Object gets notified if someValue changes.
Now I'm calling saveAction: to save. I close the App. When I restart, whats a good way to restore the 300 x addObserver?
Thanks. Regards.
EDIT: Aka, what is the best way to add observers when unarchiving CoreData entities? Custom init() in the Model Class? just fetching all Entities of Employee in a for loop an开发者_StackOverflow中文版d then call addObserver on them?
It seems like the best way to do things like this would be subclass NSManagedObject for your Employee entity and override the awakeFromFetch and awakeFromInsert methods. the awakeFromInsert gets called when you first insert the entity, so you could move your existing code to add the observers to there. The awakeFromFetch is where you would add the observers when fetching.
精彩评论