Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see values of Object in NSLog?

Suppose I have an object containing some data.

How can I see that data using NSLog?

If anyone is not clear about my question, then can ask me again.

like image 624
Chatar Veer Suthar Avatar asked Feb 28 '11 10:02

Chatar Veer Suthar


2 Answers

If you want to see an NSArray and NSDictionary and etc objects then you can directly print like NSLog(@"%@",object);

If it is an user defined object then you need to display by calling with property (attribute).

User defined object with name object and properties like

NSString *property1;
int property2;
NSMutableArray *property3;

Print them in the console as follows:

NSLog(@"%@, %d, %@" object.property1,object.property2,object.property3);

like image 129
Satya Avatar answered Oct 14 '22 13:10

Satya


If you implement the -(NSString*)description method in your class then you can use NSLog to output a summary of the data. Of course, you can also directly output any property.

For example:

NSLog (@"%@ %d", object, object.integer);

The first part calls the description method and outputs that; the second part gets the value of the integer property of object and outputs that.

like image 27
Stephen Darlington Avatar answered Oct 14 '22 13:10

Stephen Darlington