2009/11/30 Mario Kušnjer <[email protected]>: > Hi ! > > I have some trouble understanding this implementation: > > - copyWithZone:(NSZone *)zone > { > ImageAndTextCell *cell = (ImageAndTextCell *)[super copyWithZone:zone]; > cell->image = [image retain]; > return cell; > } > > It is from the Apple's sample code. > > First question is why there is no return type declared in front of > copyWithZone: (probable - id - type) ?
If you don't declare a return type for a method, it defaults to id > Second question is what this sign stands (means) for: -> (in cell->image = > [image retain];) ? cell->image is semantically identical to (*cell).image. That is, it's directly accessing the instance variable "image" of the object "cell" > Could that line be written somehow different (like any other objc message) ? In most cases, yes. However, copyWithZone: is special, the superclass' implementation just blindly copies all of the raw bits in the source object to the newly created one. If you were to use the normal -setImage: call, that old value would be released one too many times. Assigning to the instance variable in this case is the way to avoid that. > > Basically, I'm asking for a child-like explanation of this implementation. > Thanks for your answers in advance. Bye. > > > Mario Kušnjer > [email protected] > +385957051982 > > > > _______________________________________________ > > Cocoa-dev mailing list ([email protected]) > > 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/clarkcox3%40gmail.com > > This email sent to [email protected] > -- Clark S. Cox III [email protected] _______________________________________________ Cocoa-dev mailing list ([email protected]) 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 [email protected]
