• 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: Stupid objective-c question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stupid objective-c question


  • Subject: Re: Stupid objective-c question
  • From: Uli Kusterer <email@hidden>
  • Date: Sat, 24 Sep 2016 04:55:09 +0200

On 23 Sep 2016, at 01:19, Sandor Szatmari <email@hidden> wrote:
> // my .m file
> static NSString * const kMyContext = @"my fantastic context";

 This avoids the issue of having a different string in a different module and relying on details of your compiler and its optimizer. However, it can still run afoul of them, in the other direction, depending on which string you use: I've seen people do this and use the name of the property being observed as the string's value. Which is not an unlikely choice for an observation in the base class. And in that case, the optimizer might give the base class and you the same string to point to in your static variable.

 OTOH, if you use your subclass's name, you're less likely to collide. But why use the memory for the additional string and risk making the value less unique when

	void *kMyContext = &kMyContext;

is *guaranteed* to give you a unique address that nobody else's object may occupy?

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


_______________________________________________

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: Stupid objective-c question
      • From: Britt Durbrow <email@hidden>
References: 
 >Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Graham Cox <email@hidden>)
 >Re: Stupid objective-c question (From: Doug Hill <email@hidden>)
 >Re: Stupid objective-c question (From: Jens Alfke <email@hidden>)
 >Re: Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Quincey Morris <email@hidden>)
 >Re: Stupid objective-c question (From: Sandor Szatmari <email@hidden>)

  • Prev by Date: Re: Stupid objective-c question
  • Next by Date: Re: Modern API to read textClipping files
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread