Reputation: 11700
Say that I perform a fetch of all entity Employee
objects by doing: NSArray *employees = [context executeFetchRequest:request error:&error];
Then I set an instance variable in my class by doing: self.allEmployees = employees;
Then later in my app I will do some modifying to my employee objects but not through accessing self.allEmployees
. I'm modifying them from another class.
Will my self.allEmployees
array be updated to the changes I've made from another class to the employee objects? Or will my self.allEmployees
array be in the state that the employee objects were when I first performed the fetch? (I'm suspecting the later)
Upvotes: 1
Views: 395
Reputation: 8247
The array you get back from the fetch request holds references to live managed objects. Unless you change a different fetchLimit or batchSize you get an array with as many fault objects as the query would return objects.
When you access a property of one of these fault objects CoreData retrieves the actual data for all the properties transparently and returns these to you.
A managed objects always has its own most recent value that was last called save on. So if you do a modification on the self.allEmployees you need to call save on the MOC and this will broadcast the changes to all other emoployee objects.
This is also the reason why KVO works on NSManagedObject properties, because they get notfified of all saved changes that affect them.
Upvotes: 1
Reputation: 6852
If you alter the objects you receive from the fetch, and don't copy them, then yes. Those are all pointers. So you shouldn't need to do another fetch request.
If you change values of an employee, the pointer won't change. The only thing that changes is the instance variables, or properties.
Upvotes: 1