Re: What is the behavior of 'isUpdated' on an NSManagedObject?
Re: What is the behavior of 'isUpdated' on an NSManagedObject?
- Subject: Re: What is the behavior of 'isUpdated' on an NSManagedObject?
- From: Keary Suska <email@hidden>
- Date: Sat, 7 Nov 2009 10:51:09 -0700
On Nov 7, 2009, at 10:10 AM, Erwin Hogeweg wrote:
Hi,
I am wrecking my brain on a problem that boils down to the behavior
of the isUpdated flag on an NSManagedObject. What I read in the
documentation is: "The receiver has unsaved changes if it has been
updated since its managed object context was last saved." My
understanding of this is that as long as I don't execute save on
NSManagedObjectContext, the modified objects have the isUpdated flag
set.
This is not what I see in my code though (see below). The isUpdated
flag still returns false after the object had been modified. I am
clearly missing something, but what could it be?
While writing this up, I think the light went on inside my head...
The change is probably already saved behind the scene by CoreData.
If that is true, I wonder how one could ever get into a situation
where the isUpdated flag is TRUE, and a NSManagedObjectContext:save
is required.
I'll dig a little deeper, but any insight provided in the mean time
is highly appreciated.
IIRC, -isUpdated only reports true when an NSManagedObject (MO) has
been previously saved. Used on conjunction with -isInserted, this
allows you to determine the difference between a MO that is new and
never saved vs a loaded MO that has been changed. To test this, save
the context and then change the name and then check -isUpdated.
Person *person = [NSEntityDescription
insertNewObjectForEntityForName:@"Person" inManagedObjectContext:
[self managedObjectContext]];
NSLog(@"person = %@\n isUpdated = %d", [person description],
[person isUpdated]);
[person setFirstName:@"Johnny"];
NSLog(@"person = %@\n isUpdated = %d", [person description],
[person isUpdated]);
11/7/09 11:30:48 AM otest[3643] person = <Person: 0x2e08590>
(entity: Person; id: 0x2e00b00 <x-coredata:///Person/t8C2B19BF-35D0-4BF1-AF41-19898101D6024
> ; data: {
addressBookRecordID = 0;
...
firstName = nil;
...
})
isUpdated = 0
11/7/09 11:30:48 AM otest[3643] person = <Person: 0x2e08590>
(entity: Person; id: 0x2e00b00 <x-coredata:///Person/t8C2B19BF-35D0-4BF1-AF41-19898101D6024
> ; data: {
addressBookRecordID = 0;
...
firstName = Johnny;
...
})
isUpdated = 0
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden