Andrew
Andrew

Reputation: 8563

How do I show what type of object is getting returned from an array or method?

I have an array that can store different types of objects. When I retrieve that object I'd like to print that object type to the log. I can't seem to find a method that does this. I don't want to print the contents of the object.

I'd like the log to say something like "NSString" or "NSDictionary".

Upvotes: 25

Views: 13778

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243146

id anObject = [myArray objectAtIndex:42];
NSLog(@"%@", [anObject class]);

(To be totally correct, it should be:)

NSLog(@"%@", NSStringFromClass([anObject class]));

Upvotes: 39

Related Questions