Re: Problem With implementing copyWithZone
Re: Problem With implementing copyWithZone
- Subject: Re: Problem With implementing copyWithZone
- From: Chris Hanson <email@hidden>
- Date: Sun, 7 Oct 2007 19:47:39 -0700
On Oct 7, 2007, at 6:25 PM, Thaddeus Cooper wrote:
My implementation looks like:
- (id) copyWithZone:(NSZone *)zone {
id copiedWine;
copiedWine = [[[self class] allocWithZone:zone] init];
The designated initializer for NSManagedObject is -
initWithEntity:insertIntoManagedObjectContext: and not -init as your
code assumes. This means that your instance doesn't know what its
entity is, and therefore doesn't know what properties it has, which
leads to this exception:
2007-10-07 18:12:40.205 WineCellar[5988:10b] *** Terminating app due
to uncaught exception 'NSUnknownKeyException', reason: '[<Wine
0x174027e0> setValue:forUndefinedKey:]: the entity (null) is not key
value coding-compliant for the key vineyard.'
Also, you have to be extremely careful in determining what, exactly,
it means to "copy" an instance of your entity. Does it mean to create
a new, identical instance of that entity with both the same attributes
*and* the same relationships? What if your entity has relationships
with to-one inverses? Do you copy the entire object graph rooted at
that object? If so, what if the object graph isn't strictly
hierarchical?
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden