Re: Check the class of a variable?
Re: Check the class of a variable?
- Subject: Re: Check the class of a variable?
- From: John Stiles <email@hidden>
- Date: Thu, 6 Apr 2006 19:05:18 -0700
Use [myString isEqualToString:@"whatever"]
On Apr 6, 2006, at 7:02 PM, PGM wrote:
I was kind of suprised that nobody yet commented on fact that
d2kagw makes a comparison to @"NSCFArray", like:
if ( [myObject methodReturningAnNSString] == @"NSCFArray" )
I would think that this is wrong as I learned that the @".."
construction returns a pointer to a newly allocated and
autoreleased NSString. This NSString does not necessarily have to
be the same as the object you are comparing it to, even if they
would have contained the same string (because of this I always use
isEqualToString). I made a little test to see whether I was correct:
NSString *myString = @"aString";
if(myString == @"aString"){
NSLog(@"Match");
}
else{
NSLog(@"No match");
}
Running this code actually returns "Match", even though I would
think the two instances of @"aString" would be independent. Yet if
I do it another way:
NSString *anotherString = [[[NSString alloc]
initWithString:@"bString"] autorelease];
if(anotherString == @"bString"){
NSLog(@"Match");
}
else{
NSLog(@"No match");
}
This return "No match". Can anybody shed a light on this?
PGM
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden