Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outputting struct to NSLog for debugging?

I am just curious, is there a way to print via NSLog the contents of a struct?

id <MKAnnotation> mp = [annotationView annotation];
MKCoordinateRegion region = 
MKCoordinateRegionMakeWithDistance([mp coordinate], 350, 350);

I am trying to output whats in [mp coordinate] for debugging.

.

EDIT_001:

I cracked it, well unless there is another way.

CLLocationCoordinate2D location = [mp coordinate];
NSLog(@"LAT: %f LON: %f", location.latitude, location.longitude);
like image 509
fuzzygoat Avatar asked May 20 '10 14:05

fuzzygoat


1 Answers

As I am aware there's no generic way to log struct value - if you know its components you can just log them explicitly as you do with CLLocationCoordinate2D. However in your class you can implement -description and/or -descriptionWithLocale: method and log class instances:

NSLog([mp description]);
//or
NSLog(@"%@", mp);

There are also convenience methods for creating NString from some standard structures: NSStringFromCGAffineTransform, NSStringFromCGPoint, NSStringFromCGSize etc

like image 174
Vladimir Avatar answered Oct 20 '22 11:10

Vladimir