2012-03-05 18 views
7

Mam błąd w pliku implementacji dla mojego modelu, który skomentowałem. Co mogę zrobić, aby rozwiązać ten problem?Brak widocznego błędu interfejsu

Z góry dziękuję.

#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 

Odpowiedz

4

Ty zadeklarowały swoją nieruchomość operandStack jako NSMutableSet, ale nie powinno być uznane go jako NSMutableArray:

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

OK, to działało dobrze. Dziękuję Ci. – pdenlinger

1

starasz się uzyskać „ostatniego obiektu” danego NSSet - to niemożliwe, ponieważ zestawy są nieuporządkowane. Metoda lastObject nie istnieje dla NSMutableSet.

Zamiast tego możesz spróbować użyć NSMutableArray.

Powiązane problemy