Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

className method?

I have just been watching the Stanford iPhone lecture online from Jan 2010 and I noticed that the guy from Apple keeps referring to getting an objects class name using "className" e.g.

NSArray *myArray = [NSArray arrayWithObjects:@"ONE", @"TWO", nil];
NSLog(@"I am an %@ and have %d items", [myArray className], [myArray count]);

However, I can't get this to work, the closest I can come up with it to use class, is className wrong, did it get removed, just curious?

NSArray *myArray = [NSArray arrayWithObjects:@"ONE", @"TWO", nil];
NSLog(@"I am an %@ and have %d items", [myArray class], [myArray count]);

Gary

like image 276
fuzzygoat Avatar asked Jun 07 '10 16:06

fuzzygoat


1 Answers

The className method is only available on Mac OS X, not on iPhoneOS. It is usually used for scripting support, which is why it doesn't exist on the iPhone. You can use something like:

NSString* className = NSStringFromClass([myArray class]);

If you want to store the string. NSStringFromClass() isn't strictly necessary, but you should probably use it as it's the "documented" way to do things.

like image 98
Jason Coco Avatar answered Sep 23 '22 02:09

Jason Coco