• 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: PGM <email@hidden>
  • Date: Thu, 6 Apr 2006 22:02:03 -0400

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: This email sent to email@hidden
  • Follow-Ups:
    • Re: Check the class of a variable?
      • From: Andrew Farmer <email@hidden>
    • Re: Check the class of a variable?
      • From: Ondra Cada <email@hidden>
    • Re: Check the class of a variable?
      • From: John Stiles <email@hidden>
References: 
 >Check the class of a variable? (From: d2kagw <email@hidden>)

  • Prev by Date: [MEET] Next Cocoaheads, April 10, 11, and 13
  • 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