コメント行に「Objective-Cオブジェクトではない」というエラーが返されるのはなぜか完全にはわかりません。どんな助けでもいただければ幸いです。
さらに、私はObjective-Cを初めて使用しますが、これは非常にばかげた間違いである可能性が高いことを認識しています。ただし、アドバイスは役に立ちます。
#import "CalculatorBrain.h"
@interface CalculatorBrain()
@property (nonatomic, strong) NSMutableArray *operandStack;
@end
@implementation CalculatorBrain
@synthesize operandStack = _operandStack;
- (NSMutableArray *)operandStack
{
if(!_operandStack){
_operandStack = [[NSMutableArray alloc] init];
}// end if
return _operandStack;
}//end operandStack
- (void)pushOperand:(double)operand
{
NSNumber *operandObject = [NSNumber numberWithDouble:operand];
[self.operandStack addObject:operandObject];
}//end pushOperand
- (double)popOperand
{
NSNumber *operandObject = [self.operandStack lastObject];//error "Not an objective-c object"
if(operandObject) [self.operandStack removeLastObject];
return [operandObject doubleValue];
}//end popOperand
- (double)performOperation:(NSString *)operation
{
double result = 0;
if([operation isEqualToString:@"+"]){
result = [self popOperand] + [self popOperand];
} else if([operation isEqualToString:@"-"]){
double subtrahend = [self popOperand];
result = [self popOperand] - subtrahend;
} else if([operation isEqualToString:@"*"]){
result = [self popOperand] * [self popOperand];
} else if([operation isEqualToString:@"/"]){
double divisor = [self popOperand];
if(divisor) result = [self popOperand] / divisor;
}//end if
[self pushOperand:result];
return result;
}//performOperation
@end