繁体   English   中英

没有可见的界面错误

[英]No visible interface error

我已注释掉我模型的实现文件中的错误。 我该怎么做才能解决此问题?

提前致谢。

#import "CalculatorBrain.h"

@interface CalculatorBrain()
@property (nonatomic, strong) NSMutableSet *operandStack;
@end

@implementation CalculatorBrain

@synthesize operandStack = _operandStack;

- (NSMutableArray *)operandStack
{
    if (!_operandStack) {
        _operandStack = [[NSMutableArray alloc] init];
    }
    return _operandStack;
}

-(void)pushOperand:(double)operand
{
    NSNumber *operandObject = [NSNumber numberWithDouble:operand];
    [self.operandStack addObject:operandObject];
}

- (double)popOperand
{
    NSNumber *operandObject = [self.operandStack lastObject]; // No visible interface for 'NSMutableSet' declares the selector 'lastObject'
    if(operandObject)   [self.operandStack removeLastObject]; // No visible interface for 'NSMutableSet' declares the selector 'removeLastObject'
    return [operandObject doubleValue];
}

- (double)performOperation:(NSString *)operation
{
    double result = 0;

    if([operation isEqualToString:@"+"]) {
        result = [self popOperand] + [self popOperand];
    } else if ([@"*" isEqualToString:operation]) {
        result = [self popOperand] * [self popOperand];
    } else if ([operation isEqualToString:@"-"]) {
        double subtrahend = [self popOperand];
        result = [self popOperand] - subtrahend;
    } else if ([operation isEqualToString:@"/"]) {
        double divisor = [self popOperand];
        if (divisor)result = [self popOperand] / divisor;
    }

    [self pushOperand:result];

    return result;

}


@end

您已经将您的operandStack属性声明为NSMutableSet ,但是应该将其声明为NSMutableArray

@property (nonatomic, strong) NSMutableArray *operandStack;

您正在尝试获取NSSet的“最后一个对象”-这是不可能的,因为集合是无序的。 NSMutableSet不存在lastObject方法。

您可能想尝试使用NSMutableArray。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM