Re: newbie - confused by copyWthZone
Re: newbie - confused by copyWthZone
- Subject: Re: newbie - confused by copyWthZone
- From: Philippe Mougin <email@hidden>
- Date: Tue, 2 Mar 2004 10:21:09 +0100
Denis,
In your case, your object must implement the NSCopying protocol.
You state that your class inherits from NSObject and that NSObject
implements copyWithZone:. The problem is that the copyWithZone: method
implemented by NSObject is a class method (denoted by a + sign before
its name in the documentation and headers), not an instance method. A
class method apply to class objects. You inherit from this method, but
at the class level, not at the instance level (i.e., your can invoke
copyWithZone: on your Hires class object, but not on instances of
Hires).
You will have to implement a copyWithZone: instance method for your
custom class.
For relevant documentation on how to do that see:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
Concepts/HowToImplCopy.html
and:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
Tasks/ImplementCopy.html
Best,
Philippe Mougin
> I'm having trouble understanding what is required to have my class
> understand "copyWithZone"
> [...]
> Now my class Hires inherits from NSObject, and NSObject
> implements copyWithZone, so why isn't that good enough?
>
> In fact if I look up NSObject's copy with zone it says "You should
> not override this method" which suggests to my inexperienced
> eye that NSObject's copyWithZone will be good enough for
> my Hires object.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.