Re: Calling getter on const object
Re: Calling getter on const object
- Subject: Re: Calling getter on const object
- From: David Duncan <email@hidden>
- Date: Mon, 8 Nov 2010 09:13:16 -0800
On Nov 8, 2010, at 9:04 AM, Jonny Taylor wrote:
> In this particular case I don't have much choice in the matter - the standard behaviour of blocks is to provide 'const' access to variables declared outside the block (and with good reason I think). In the example I gave, I want to access the property from within a block. I can work around it as shown in my example, or declare the function parameter (frame object pointer) with the __block prefix, but I feel that neither should be necessary.
Blocks don't redeclare values as 'const', it makes copies of those values for the block's own use. That is what is meant by providing 'const' access – if you change the variables, you won't see that change reflected in the originals. For objects the copied value is just a pointer (the object will be retained) so the 'const' access is usually a moot point, since you don't care about the pointer not changing, you care about the object not changing. There is no direct support for const objects in Blocks – if you have an object pointer, you are free to change the object to your heart's content.
So as I surmised when I asked the question, you don't need the 'const' modifier at all. Just declare and use the variable normally.
--
David Duncan
_______________________________________________
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