大约一周前我开始了 Objective-C 编程,并且一直坚持从传递给函数的字符串数组创建一个新字符串。我已经对此进行了彻底的研究,似乎无法弄清楚为什么我可以使用stringByAppendingString
一次(检查NSLog
)但不能第二次使用而不抛出此错误:
感谢您的关注。
2012-06-29 20:46:35.761 计算器[32883:f803]-[__NSCFNumber stringByAppendingString:]:无法识别的选择器发送到实例 0x6e43d50
2012-06-29 20:46:35.763 计算器 [32883:f803] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSCFNumber stringByAppendingString:]:无法识别的选择器发送到实例 0x6e43d50”
+ (NSString *)descriptionOfTopOfStack:(NSMutableArray *)stack
{
NSString *result;
NSString *displayString = [[NSString alloc]init];
id topOfStack = [stack lastObject];
if (topOfStack) [stack removeLastObject];
if ([self isNoOperandOperation:topOfStack]) {
displayString = [displayString stringByAppendingString:topOfStack];
result = displayString;
}
else if ([self isOperation:topOfStack]){
id nextInStack = [stack lastObject];
if (topOfStack) [stack removeLastObject];
displayString = [displayString stringByAppendingString:nextInStack];
displayString = [displayString stringByAppendingString:topOfStack];
result = displayString;