ios 没有可见的界面错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9574597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:10:34  来源:igfitidea点击:

No visible interface error

iosxcode

提问by pdenlinger

I have an error in the implementation file for my model which I have commented out. What can I do to fix this problem?

我的模型的实现文件中有一个错误,我已经注释掉了。我能做些什么来解决这个问题?

Thanks in advance.

提前致谢。

#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

采纳答案by rob mayoff

You have declared your operandStackproperty as an NSMutableSet, but you should have declared it as an NSMutableArray:

您已将您的operandStack财产声明为NSMutableSet,但您应该将其声明为NSMutableArray

@property (nonatomic, strong) NSMutableArray *operandStack;

回答by Alex Coplan

You are trying to get the "last object" of an NSSet- this is impossible, as sets are unordered. The method lastObjectdoes not exist for NSMutableSet.

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

You might want to try using an NSMutableArray instead.

您可能想尝试使用 NSMutableArray 代替。