• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Calling getter on const object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Calling getter on const object
      • From: Jonny Taylor <email@hidden>
References: 
 >Calling getter on const object (From: Jonny Taylor <email@hidden>)
 >Re: Calling getter on const object (From: David Duncan <email@hidden>)
 >Re: Calling getter on const object (From: Jonny Taylor <email@hidden>)
 >Re: Calling getter on const object (From: David Duncan <email@hidden>)
 >Re: Calling getter on const object (From: Jonny Taylor <email@hidden>)

  • Prev by Date: Re: Interrupt copyItemAtPath
  • Next by Date: Re: MapKit on iPad
  • Previous by thread: Re: Calling getter on const object
  • Next by thread: Re: Calling getter on const object
  • Index(es):
    • Date
    • Thread