Objective-C 新手,正在开发 iOS5 的编程计算器。
使用常规的旧数字一切正常:
- (void)pushOperand:(double)operand
{
[self.programStack addObject:[NSNumber numberWithDouble:operand]];
}
但是当我创建一个包含变量测试编号的字典时,如下所示:
- (void) pushOperandAsVariable:(NSObject *)variable
{
//Create dictionary
NSArray *objects = [[NSArray alloc] initWithObjects:[NSNumber numberWithDouble:3],[NSNumber numberWithDouble:4.1],[NSNumber numberWithDouble:-6],[NSNumber numberWithDouble:4.5298], nil];
NSArray *keys = [[NSArray alloc] initWithObjects:@"x",@"y",@"z",@"foo", nil];
NSDictionary *variableValues = [[NSDictionary alloc] initWithObjects:objects forKeys:keys];
NSNumber *operand;
//Check variableValues for keys
for (int i=0; i<keys.count; i++)
{
if ([keys objectAtIndex:i]==variable)
operand = [variableValues objectForKey:variable];
}
NSLog(@"%@, %@",variable,operand);
[self.stackOfThingsSinceLastClear addObject:operand];
}
倒数第二行的 NSLog 总是出现“x, (null)”。我错过了什么,我的操作数正在消失?