我正在尝试从 JSON 调用中打印/访问我的(双)值并获取:
[事件纬度]:无法识别的选择器发送到实例 0x8d09970
从同一个对象访问字符串值时,它打印得很好。在调试器中,我看到我的值和 event.latitude 被映射为双精度的 NSCFNumber。我不知道这是否只是我没有正确地投射或声明纬度,还是没有正确映射该值。弦乐工作
这是一些代码:
event.h
@interface Event : NSObject {
NSNumber *latitude;
}
@property (nonatomic, retain) NSNumber *latitude;
@end
ViewController.m 片段
Event *event = (Event *)[eventsArray objectAtIndex:indexPath.row];
static NSNumberFormatter *numberFormatter;
if (numberFormatter == nil) {
numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setMaximumFractionDigits:3];
}
NSLog(@"Event - %@", event.name ); //This works just fine
NSLog(@"Event - %@", event.latitude ); //This is where I am testing different ways of accessing the latitude
NSLog(@"Event - %@", [numberFormatter stringFromNumber:[event latitude]] );
//NSLog(@"Event - %@", [[event latitude] stringValue] );
NSString *coordinatesString = [[NSString alloc] initWithFormat:@"Lat:%@, Lon:%@",
[numberFormatter stringFromNumber:[event latitude]],
[numberFormatter stringFromNumber:[event longitude]]];