开发者

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

开发者 https://www.devze.com 2022-12-17 17:45 出处:网络
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 pri

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 s开发者_StackOverflowomething like "NSString" or "NSDictionary".


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

(To be totally correct, it should be:)

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

精彩评论

暂无评论...
验证码 换一张
取 消