• 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: Check the class of a variable?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >Check the class of a variable? (From: d2kagw <email@hidden>)
 >Re: Check the class of a variable? (From: PGM <email@hidden>)

  • Prev by Date: Re: Check the class of a variable?
  • Next by Date: Re: Check the class of a variable?
  • Previous by thread: Re: Check the class of a variable?
  • Next by thread: Re: Check the class of a variable?
  • Index(es):
    • Date
    • Thread