NSNumber に変換したい NSSTRING に単純な値があります。私は自分のコードでこれを常に行っていますが、何らかの理由で今回は機能していません。これで何か問題があると思いますか?
NSNumberFormatter * num_formatter = [[NSNumberFormatter alloc] init];
[num_formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *score;
NSString *mystr = [[player ScoresArray] objectAtIndex:currentKeeper - 1];
NSLog(@"here is my string: -%@-", mystr);
score = [num_formatter numberFromString:mystr]; // crash occurs on this line. see error below...
NSLog(@"now it is: %d", [score intValue]); // it never gets to this line...
上記のコードからの出力は次のとおりです。
ここに私の文字列があります: -3-
これが私が得るエラーです:
2013-02-26 17:21:48.912 Golf Whiz[50407:c07] -[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xcb5fa90
2013-02-26 17:21:48.912 Golf Whiz[50407:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xcb5fa90'
*** First throw call stack: