Search code examples
iosclasscastingnsstringnslog

How to determine the structure of an iOS (id) object?


When I call a certain function from my iOS app, it returns an id data type. I can't see into this function so I don't know what it's doing or what the return type really is.

If I print it to console using NSLog("@"...) I get a string similar to this: 2012-01-18 19:03:08.915 HelloWorld[165:707] Key Press State.

Is there any way for me to determine the structure of this basic Id object? How would I go about getting a specific part of that response out, such as "Key press state". String parsing seems like a horrible idea, but maybe that's the only way. Perhaps the data really is just an NSString?

Thanks!


Solution

  • Try this:

    NSLog(@"Mystery object is a %@", NSStringFromClass([mysteryObject class]));