Re: Overriding -copyWithZone: the right way
Re: Overriding -copyWithZone: the right way
- Subject: Re: Overriding -copyWithZone: the right way
- From: "M. Uli Kusterer" <email@hidden>
- Date: Fri, 5 Nov 2004 23:09:27 +0100
At 13:52 Uhr -0500 05.11.2004, Jean-Olivier Lanctôt wrote:
Is there an Apple document that tells us how to do it exactly?
I know we must return an object identical to "self" ... but do we
invoke super copyWithZone? etc. etc.
Well, googling a little, the best docs are probably in:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/ImplementCopy.html
and then there's a little more in:
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSObject.html#copy
<<
(id)copy
Convenience method for classes that adopt the
NSCopying protocol. This method returns the
object returned by the NSCopying protocol method
copyWithZone: where the zone is nil. An exception
is raised if there is no implementation for
copyWithZone:.
NSObject does not itself support the NSCopying
protocol. Subclasses must support the protocol
and implement the copyWithZone: method. A
subclass version of the copyWithZone: method
should send the message to super first, to
incorporate its implementation, unless the
subclass descends directly from NSObject.
More info in
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Protocols/NSCopying.html#//apple_ref/doc/uid/20000053/BCIJFCDH
<<
- (id)copyWithZone:(NSZone *)zone
Returns a new instance that's a copy of the
receiver. Memory for the new instance is
allocated from zone, which may be nil. If zone is
nil, the new instance is allocated from the
default zone, which is returned from the function
NSDefaultMallocZone. The returned object is
implicitly retained by the sender, who is
responsible for releasing it. The copy returned
is immutable if the consideration "immutable vs.
mutable" applies to the receiving object;
otherwise the exact nature of the copy is
determined by the class.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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