我是一个使用 RPN 计算器的新手,我正在尝试设置一个由两个成员数组组成的数组来存储字符串/值对,以便以后可以使用它们来显示按下的数字/运算符的完整序列到达用户现在所在的任何地方。问题是,无论我做错了什么都意味着数组不会填充。关于如何解决这个问题的任何想法?
这是我的代码(oneStringValuePair
并且arrayOfStringValuePairs
是在 .h 中声明(nonatomic, strong)
并在 .m 中合成的 NSMutableArrays):
NSLog(@"result is float: %f",result);
self.formattedNumber = [NSString stringWithFormat:@"( %@%@%@ )",firstNumber,operation,secondNumber];
NSLog(@"String is %@",self.formattedNumber);
NSMutableArray *pair = self.oneStringValuePair;
NSMutableArray *array = self.arrayOfStringValuePairs;
pair = [pair init];
array = [array init];
if(pair==nil)
{
NSLog(@"pair is nil.");
}
if (array==nil)
{
NSLog(@"array is nil.");
}
[pair addObject:self.formattedNumber];
NSLog(@"first array element description: %@", [[pair lastObject] description]);
[pair addObject:[NSNumber numberWithFloat:result]];
NSLog(@"second array element description: %@",[[pair lastObject] description]);
NSLog(@"pair count: %@",self.oneStringValuePair.count);
if (self.arrayOfStringValuePairs)
{
[array addObject:pair];
}
NSLog(@"count of pairs: %@",array.count);
这是 NSLog 的5 3 + 6 /
:
2012-08-04 08:02:54.550 Calculator[83891:f803] result is float: 8.000000
2012-08-04 08:02:54.552 Calculator[83891:f803] String is ( 3+5 )
2012-08-04 08:02:54.552 Calculator[83891:f803] pair is nil.
2012-08-04 08:02:54.553 Calculator[83891:f803] array is nil.
2012-08-04 08:02:54.554 Calculator[83891:f803] first array element description: (null)
2012-08-04 08:02:54.555 Calculator[83891:f803] second array element description: (null)
2012-08-04 08:02:54.555 Calculator[83891:f803] pair count: (null)
2012-08-04 08:02:54.556 Calculator[83891:f803] count of pairs: (null)
2012-08-04 08:02:55.987 Calculator[83891:f803] result is float: 0.750000
2012-08-04 08:02:55.988 Calculator[83891:f803] String is ( 6/8 )
2012-08-04 08:02:55.989 Calculator[83891:f803] pair is nil.
2012-08-04 08:02:55.990 Calculator[83891:f803] array is nil.
2012-08-04 08:02:55.991 Calculator[83891:f803] first array element description: (null)
2012-08-04 08:02:55.992 Calculator[83891:f803] second array element description: (null)
2012-08-04 08:02:55.993 Calculator[83891:f803] pair count: (null)
2012-08-04 08:02:55.994 Calculator[83891:f803] count of pairs: (null)