views:

124

answers:

1

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);

many thanks

gary

+2  A: 

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

Vladimir
Thank you Vladimir, very helpful.
fuzzygoat