NSCopyObjectEdit

- (id)copyWithZone:(NSZone *)aZone
{
    id thing = [super copyWithZone:aZone];
    [thing setVar:[NSColor greyColor]];
    return thing;
}
  • Use dereferencing instead:
- (id)copyWithZone:(NSZone *)aZone
{
    id thing = [super copyWithZone:aZone];
    thing->var = [var copyWithZone:aZone];
    return thing;
}
  • This advice is applicable more generally as well:
    • Don't use public accessor methods in init methods
    • This is because subclasses would otherwise have to worry within their accessor methods about whether or not they were fully initialized at the time those accessors were used
    • Don't use them in copyWithZone: either because that method is effectively the init method of the new object
    • This doesn't break encapsulation because it's just like referring to self from within init