Update: note that the actual problem here wasn’t with core data more with a bad property declaration of mine – strong/weak – that resulted in the object being released between viewWillLoad and viewDidLoad of the new view.
I’m working through Tim Isted’s book on Core Data in iOS and have been doing fine up until now. I’m trying to follow how the new viewController uses a second managedObjectContext – editingContext in the below – to capture changes in the text fields before saving.
- (void)setCurrentPerson:(AWPerson *)aPerson {
if( !aPerson )
{
aPerson = [AWPerson randomPersonInManagedObjectContext:self.editingContext];
}
else if( [aPerson managedObjectContext] != self.editingContext ) {
self.title = @"Edit person";
aPerson = (id)[self.editingContext objectWithID:[aPerson objectID]];
}
[...]
}
At this point:
aPerson = (id)[self.editingContext objectWithID:[aPerson objectID]];
when I print the description in the debugger for aPerson I should get
<AWPerson: 0x6b5de70> (entity: Person; id: 0x6b5bb60 <x-coredata://A6EC85F2-81A8-488F-B2E3-F82687C252A2/Person/p1> ; data: {
dateOfBirth = "1973-11-03 12:53:58 +0000";
eyeColor = "(...not nil..)";
firstName = Peter;
lastName = Dickens;
yearOfBirth = 1973;
instead I get the following where <fault> has replaced the values
<AWPerson: 0x6b609d0> (entity: Person; id: 0x6b5bb60 <x-coredata:
//A6EC85F2-81A8-488F-B2E3-F82687C252A2/Person/p1> ; data: <fault>)
I really can’t see what’s happening. Before the line aPerson has the values, after the line, they are replaced. Any help would be greatly appreciated.
Thanks, Steve
I do not have that book, but I’ll try to help…
However, it does not look wrong to me. It looks like exactly what I would expect (assuming aPerson lives in a different context when setCurrentPerson is called). I’ll try to walk through the code you posted. Maybe I can some how determine what your question is, and somehow provide an answer in the process. My comments are included in the code as, well, comments.