I don't know if all those tests are necessary. I did show the method to a Core Data engineer at WWDC one year and he thought it looked OK.
Those are good points about -prepareForDeletion. I was just experimenting for the heck of it. I guess if it ain't broke I shouldn't fix it. :) On Oct 22, 2011, at 10:45 AM, Jerry Krinock wrote: > >> - (BOOL)retainedObjectHasBeenDeleted >> { >> // if object has been deleted, then it no longer exists >> if ([self isDeleted]) return YES; >> // otherwise, see if object with this ID exists in the database >> NSManagedObjectContext *context = [self managedObjectContext]; >> if (context == nil) return YES; >> NSManagedObjectID *objectID = [self objectID]; >> if (objectID == nil) return YES; >> NSManagedObject *obj = [context objectRegisteredForID:objectID]; >> return obj == nil; >> } > > Interesting, David. > > Why do you check for the object ID? Have you ever seen an object which > passed the first two tests (not isDeleted, has MOC), but then didn't have an > objectID? How could that happen? > >> I'm currently experimenting with the following to see if it's as safe and >> perhaps faster∑ > > Are you having performance issues with your original > -retainedObjectHasBeenDeleted? > > In my world, -retainedObjectHasBeenDeleted is only going to be invoked in > corner cases, but documentation states that -prepareForDeletion is invoked > "when the receiver is about to be deleted". That may be quite often in some > use cases. Also, there is another definition trap there ˆ what does "when > the receiver is about to be deleted" mean? How will that be interpreted by > an Apple engineer who adds some new object-deleting method to support iCloud > 2.0 in Mac OS 10.8? Plus, what Dave Fernandes noted. > > I think that your original -retainedObjectHasBeenDeleted is fine and I > wouldn't mess with it if I were you. > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com