Tutorial :How to get class and runtime information?


For debugging purposes, I'd like to display as much class information as I can, and possibly runtime information (which thread does the class/function run in, etc) into the console.

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

P.S: I'm using Cocoa Touch.


in a class, if you overload the -(NSString *)description method, you can easily log class info with NSLog(@"%@", some_object);

here's a fictitious 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 what thread the method is being called on.

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

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »