2012-03-05 12 views
7

मुझे अपने मॉडल के लिए कार्यान्वयन फ़ाइल में एक त्रुटि है जिसे मैंने टिप्पणी की है। इस समस्या को सुलझाने में मैं क्या कर सकता हूं?कोई दृश्य इंटरफ़ेस त्रुटि

अग्रिम धन्यवाद।

#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 

उत्तर

4

आप एक NSMutableSet के रूप में अपने operandStack संपत्ति घोषित किया है, लेकिन आप एक NSMutableArray के रूप में यह घोषित किया जाना चाहिए था:

@property (nonatomic, strong) NSMutableArray *operandStack; 
+0

ठीक है, यह ठीक काम किया। धन्यवाद। – pdenlinger

1

आप एक NSSet के "अंतिम वस्तु" की कोशिश कर रहे हैं - यह है असंभव, सेट सेट unordered हैं। विधि lastObject NSMutableSet के लिए मौजूद नहीं है।

आप इसके बजाय एक एनएसएमयूटेबलएरे का उपयोग करने का प्रयास करना चाहेंगे।

संबंधित मुद्दे