Re: Stupid objective-c question
Re: Stupid objective-c question
- Subject: Re: Stupid objective-c question
- From: Quincey Morris <email@hidden>
- Date: Wed, 21 Sep 2016 16:51:31 -0700
- Feedback-id: 167118m:167118agrif8a:167118sS5zSm_QeE:SMTPCORP
On Sep 21, 2016, at 16:44 , Gabriel Zachmann <email@hidden> wrote:
>
> how can the compiler know that '==' in this case is a NSString comparison?
It can’t because it isn't. What’s being compared are raw pointers. The string value is irrelevant.
> Or is some other magic going on here? if so, which?
No magic, but a (not very good) assumption, that literal strings are unique at run time, so a pointer to a particular literal string is a globally unique identifier.
Incidentally, this assumption is true only within a target. Literal strings in different targets may have different pointers.
So, this technique is generally Not A Good Idea™.
_______________________________________________
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