All-
First of all, I am not sure this is the right place to post this question, but I didn't see a one for iPhone or Core Data, so bear with me.
I ran into an issue with managed objects, and I am not even sure whether this is expected iPhone SDK (3.0) behavior, or a user error. Please refer to the code below.
The issue is that I don't expect the isInserted flag to have changed when viewWillDisappear is called. I hit the navigation back button as soon as the view appears, no additional code is executed. It is almost as if I am looking at a different object, but the object references in viewDidLoad and in viewWillDisappear are the same.
I have read the Core Data Programming Guide, and the Class References documentation, but I am obviously still be missing something.
Can somebody please shed some light on this?
Any help is highly appreciated.
Regards,
Erwin
-(void)viewDidLoad{ [super viewDidLoad]; ... MyObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:@"MyObject" inManagedObjectContext:managedObjectContext]; myObject = newObject; // Added to inspect oject reference [myObject retain]; NSLog(@"viewDidLoad - isUpdated: %d", [myObject isUpdated]); NSLog(@"viewDidLoad - isInserted: %d", [myObject isInserted]); [myObject setSomeAttribute:[NSDate date]]; ... }
-(void)viewWillAppear:(BOOL)animated{ NSLog(@"viewWillAppear"); }
-(void)viewWillDisappear:(BOOL)animated{ NSLog(@"viewWillDisappear - isUpdated: %d", [myObject isUpdated]); NSLog(@"viewWillDisappear - isInserted: %d", [myObject isInserted]); // Expect this to be TRUE ... }
2009-08-16 08:28:36.287 CDTestApp[18000:20b] viewDidLoad - isUpdated: 0 2009-08-16 08:28:36.297 CDTestApp[18000:20b] viewDidLoad - isInserted: 1 2009-08-16 08:28:36.305 CDTestApp[18000:20b] viewWillAppear 2009-08-16 08:28:42.777 CDTestApp[18000:20b] viewWillDisappear - isUpdated: 0 2009-08-16 08:28:42.778 CDTestApp[18000:20b] viewWillDisappear - isInserted: 0 <----- expected this to be 1
|