我試圖打印從JSON呼叫/訪問我的(雙)值,並得到:錯誤打印NSCFNumber鑄成的NSNumber使用NSNumberFormatter和RestKit
[事件緯度]:無法識別的選擇發送到實例0x8d09970
從同一對象訪問字符串值時,它打印得很好。在調試器中,我看到我的值和event.latitude被映射爲來自double的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]]];
你釘了它。我有動態的自由;並應該已經合成。其他屬性是合成的。 – Nungster