Structure output in NSLog for debugging?

I'm just wondering if there is a way to print the contents of a structure through NSLog?

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

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

.

EDIT_001:

I hacked it, well, if there is no other way.

 CLLocationCoordinate2D location = [mp coordinate]; NSLog(@"LAT: %f LON: %f", location.latitude, location.longitude); 

many thanks

Gary

+6
objective-c iphone cocoa-touch
source share
1 answer

As I understand it, there is no general way to register a struct value - if you know its components, you can simply write them explicitly, as you do with CLLocationCoordinate2D . However, in your class you can implement the -description and / or -descriptionWithLocale: methods and log class instances:

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

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

+14
source share

All Articles