Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSLog and printing of an object

Tags:

objective-c

I have a class and I want to setup what is printed when I call NSLog with that class. For example,

NSLog(@"%@",nonstandardObject);

How do I setup the object so it prints out what I'd want?

like image 240
devinross Avatar asked Oct 18 '09 04:10

devinross


1 Answers

Override the -description method. It takes no parameters and returns an NSString that get's printf'd out.

There's another variant called -debugDescription (returns NSString, no parameters) that's used when po'ing the object from gdb.

like image 97
Dave DeLong Avatar answered Nov 15 '22 07:11

Dave DeLong