NSManagedObject isDeleted returns NO after deleting object?
NSManagedObject isDeleted returns NO after deleting object?
- Subject: NSManagedObject isDeleted returns NO after deleting object?
- From: Jim Correia <email@hidden>
- Date: Thu, 14 Jul 2005 15:15:56 -0400
If I insert a managed object into a context, then delete it (without
ever having saved the context), [object isDeleted] returns NO.
Likewise [managedObjectContext deletedObjects] is empty.
This also results in the paradoxical situation where in the
NSManagedObjectContextObjectsDidChangeNotification there may be
objects in the deleted objects list (NSDeletedObjectsKey) who return
NO for [object isDeleted].
Is this a bug (which I'll go off and report ASAP) or am I
misunderstanding something?
Thanks,
Jim
- (void)managedObjectContextObjectsDidChange:(NSNotification *)
notification
{
NSSet *deletedObjects = [[notification userInfo]
objectForKey: NSDeletedObjectsKey];
NSEnumerator *deletedObjectsEnumerator = [deletedObjects
objectEnumerator];
NSManagedObject *object;
while (nil != (object = [deletedObjectsEnumerator nextObject]))
{
if (! [object isDeleted])
{
NSLog(@"!!!");
NSLog(@"!!! Object appears in deleted objects list, but
isDeleted returned NO. %@", object);
NSLog(@"!!!");
}
}
}
- (IBAction)demonstrateBug:(id)sender
{
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *object = nil;
// simulate the user creating an item by pressing the "New
Person" button
object = [NSEntityDescription insertNewObjectForEntityForName:
@"Person" inManagedObjectContext: context];
[context processPendingChanges];
NSLog(@"* After Insert *");
NSLog(@"Inserted Objects: %@", [context insertedObjects]);
NSLog(@"Deleted Objects: %@", [context deletedObjects]);
NSLog(@"Object isInserted = %d, isDeleted = %d", [object
isInserted], [object isDeleted]);
NSLog(@"===");
// delete the object
[context deleteObject: object];
[context processPendingChanges];
NSLog(@"* After Delete *");
NSLog(@"Inserted Objects: %@", [context insertedObjects]);
NSLog(@"Deleted Objects: %@", [context deletedObjects]);
NSLog(@"Object isInserted = %d, isDeleted = %d", [object
isInserted], [object isDeleted]);
NSLog(@"===");
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden