How to get class and runtime information?

For debugging purposes, I would like to display as much information about the class as possible, and possibly information about the runtime (which thread the class / function performs, etc.) in the console.

Is there an easy way to do this with a function, variable, or even an (external) structure?

PS: I use Cocoa Touch.

+6
debugging objective-c iphone cocoa-touch xcode
source share
1 answer

in a class, if you overload the method -(NSString *)description , you can easily write class information using NSLog(@"%@", some_object);

here's a dummy example:

 -(NSString *)description { return [NSString stringWithFormat:@"%@, %@, %d", [super description], class.object_ivar, class.int_ivar]; } 

You can use standard C macros to get things like name, file, line number, etc ... use the NSThread classes to get information about which thread the method is being called on.

I posted this twitter. http://twitter.com/kailoa/status/1349928820 Feel free to follow me if you are interested in more tidbits. I try to raise them regularly.

 #define METHOD_LOG (NSLog(@"%@ %s\n%@", NSStringFromSelector(_cmd), __FILE__, self)) 
+8
source share

All Articles