Re: Stupid objective-c question
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