副标题:为什么这段代码有效?它似乎允许通过某种强制NSNumber
与类型进行比较。NSString
我正在尝试将 a 中的选择UISegmentedControl
与先前存储的值进行比较。
- (IBAction)minSegmentedControlChanged:(id)sender // MINIMUM value
{
UISegmentedControl *s1 = (UISegmentedControl *)sender;
NSMutableArray *pD = [[GameData gameData].curData valueForKey:@"persData"];
// Must make sure max >= min
NSNumber *currMax = [pD objectAtIndex:1];
NSLog(@"%@", [currMax class]); // __NSCFString ?!
int ss1 = s1.selectedSegmentIndex;
NSNumber *SS1 = [NSNumber numberWithInt:ss1 + 2];
if (SS1 >= currMax) SS1 = currMax;
NSLog(@"%@", SS1); // Answer is correct, appears to be an integer
NSLog(@"%@", [SS1 class]); // __NSCFString ?!
[pD replaceObjectAtIndex:0
withObject:SS1];
[[GameData gameData].curData setObject:pD
forKey:@"persData"];
NSLog(@"%@", [[GameData gameData].curData valueForKey:@"persData"]);
}
我特别想问:
NSNumber *currMax = [pD objectAtIndex:1];
NSLog(@"%@", [currMax class]); // __NSCFString ?!
这似乎返回一个数字的字符串。 [[GameData gameData].curData valueForKey:@"persData"];
初始化如下:
_persData = [[NSMutableArray alloc] initWithObjects:@"2", @"8", @"TWL", @"0", @"0", nil];
这是元素 1 处的字符串。那么为什么我可以向它询问 an NSNumber
,它报告它实际上是__NSCFString
我可以在其上进行算术比较的 a 呢?我只在objective-c工作了几个月,但这似乎很奇怪。