|
From: Jonathan P. <jp...@dc...> - 2005-12-05 17:15:09
|
On 5 Dec 2005, at 16:36, kimura wataru wrote:
> In Objective-C, "==" operator for Cocoa objects tests by address. We
> can test values of strings with "isEqualToString:" method.
>
> I guess the objc compiler makes same address to literal string @"YES".
>
> Rupert BARROW wrote:
>> What is going on ? I have made every effort for the two ObjC and
>> RubyCocoa strings be equal : same value ("YES"), same class
>> (NSCFString); what else ? Why does the test
>> if ([record valueForKey:@"changed"] == @"YES")
>> never verify ?
I think I mentioned something like this being broken a short while
ago (even though it comes from Apple's sample code - grr!).
As far as I know, it works sometimes because some strings are
'interned', and so the literal @"YES" NSString/CFString object is
actually the same one being returned from the valueForKey: method.
Relying on this behaviour is not good.
|