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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With