将结构输出到NSLog进行调试?

时间:2010-05-20 14:01:44

标签: iphone objective-c cocoa-touch

我只是很好奇,有没有办法通过NSLog打印结构的内容?

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

我正在尝试在[mp coordinate]输出什么用于调试。

EDIT_001:

我破解了它,除非有另一种方法。

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

1 个答案:

答案 0 :(得分:15)

我知道没有通用的方法来记录结构值 - 如果你知道它的组件,你可以像使用CLLocationCoordinate2D一样明确地记录它们。但是在您的课程中,您可以实现-description和/或-descriptionWithLocale:方法和日志类实例:

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

还有从一些标准结构创建NString的便捷方法:NSStringFromCGAffineTransformNSStringFromCGPointNSStringFromCGSize