我正在嘗試從iTunes U iPhone編程講座中學習。ARC與非ARC removeLastObject方法
有,我在關於以下方法的代碼的問題:
+(double) popOperandOffStack:(NSMutableArray *) stack{
double result = 0;
id topOfStack = [stack lastObject];
if (topOfStack) [stack removeLastObject];
if ([topOfStack isKindOfClass:[NSNumber class]]){
result = [topOfStack doubleValue];
}
else if ([topOfStack isKindOfClass:[NSString class]]){
if ([topOfStack isEqualToString:@"+"]){
result = [self popOperandOffStack:stack] + [self popOperandOffStack:stack];
}
if ([topOfStack isEqualToString:@"-"]){
result = [self popOperandOffStack:stack] - [self popOperandOffStack:stack];
}
if ([topOfStack isEqualToString:@"*"]){
result = [self popOperandOffStack:stack] * [self popOperandOffStack:stack];
}
if ([topOfStack isEqualToString:@"/"]){
result = [self popOperandOffStack:stack]/[self popOperandOffStack:stack];
}
}
return result;
}
如何topOfStack即使removeLastObject已經調用它仍然可以訪問。在過去,removeLastObject會向已刪除的對象發送一個版本,那麼topOfStack如何仍然有效?我猜這是與ARC相關的,但我不確定。