• 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:15:05 +0200

On 22 Sep 2016, at 02:02, Doug Hill <email@hidden> wrote:
>>> My question is: how can the compiler know that '==' in this case is a NSString comparison?
>>> Or is some other magic going on here? if so, which?
>>> Does the compiler know it should perform some kind of dynamic method dispatch?
>>
>> My guess, without seeing the code that set up the observer, is that it was also set up with @"mediaLibraryLoaded", and the compiler collects and reuses string constants, so the address is the same. I'd guess that if you ensure that the string is a unique variable, it won't work.
>>
>> NSString* s = [NSString stringWithFormat:@"%@%@%@", @"media", @"Library", @"Loaded"];
>> if(context == (__bridge void*)s)
>>
>> Steve via iPad
>
> For the above test, you could also try turning off the LLVM code-gen setting "gcc_reuse_strings".
> (Which parenthetically, you probably wouldn't want to do in shipping code, particularly if you have a lot of strings.)
>
> But yeah, as everyone says, it's generally not a good thing to rely upon this behavior, and just use -[NSString isEqual:]

 Do *not* call methods on the context to a KVO observation! It is not guaranteed to actually be an object! It is not storage for user data, it is simply a unique identifier for your subscription to these KVO callbacks.

-- Uli
_______________________________________________

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


References: 
 >Stupid objective-c question (From: Gabriel Zachmann <email@hidden>)
 >Re: Stupid objective-c question (From: Steve Mills <email@hidden>)
 >Re: Stupid objective-c question (From: Doug Hill <email@hidden>)

  • Prev by Date: Re: Stupid objective-c question
  • Next by Date: Re: Stupid objective-c question
  • Previous by thread: Re: Stupid objective-c question
  • Next by thread: Re: Stupid objective-c question
  • Index(es):
    • Date
    • Thread