Re: copyWithZone - if anyone could explain this to me ?
Re: copyWithZone - if anyone could explain this to me ?
- Subject: Re: copyWithZone - if anyone could explain this to me ?
- From: Clark Cox <email@hidden>
- Date: Mon, 30 Nov 2009 20:15:17 -0500
2009/11/30 Mario Kušnjer <email@hidden>:
> 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@hidden
> +385957051982
>
>
>
> _______________________________________________
>
> 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
>
--
Clark S. Cox III
email@hidden
_______________________________________________
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