No visible declaration error when the declaration is there, Objective c [closed]
-
22-06-2021 - |
Frage
Hi I am getting the the error "No visible @interface for 'CalculatorBrain" declares the selector 'runprogram:usingVariableValues:'" at the graphPoint.y code part
-(id) programToGraph:(GraphingView *)sender{
CGPoint graphPoint;
for( int x =-100;x<100; x++)
{
NSDictionary* xValue = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:x] forKey:@"X", nil];
graphPoint.x =x;
//error occurs here
graphPoint.y = [self.graphingPoint runProgram: [self.graphingPoint program] usingVariableValues:xValue];
}
}
I passed self.graphingPoint via segue and protocols so it has the same value as the object 'CalculatorBrain' which is in a different MVC and calls runprogram:usingVariableValues. My implementation for calculatorBrain has the method above and works in its own viewController but when I call it in this new viewController via protocol method it says I dont declare it in CalculatorBrain. Here is the original declaration
@interface CalculatorBrain : NSObject
- (void)pushOperand:(double)operand;
- (double)performOperation:(NSString *)op;
@property (nonatomic, readonly) id program;
+ (NSString *)descriptionOfProgram:(id)program;
+ (double)runProgram:(id)program usingVariableValues: (NSDictionary*) variableValues;
@property (nonatomic, strong) NSDictionary* testVariableValues;
- (void) testValue : (NSString*) test;
-(void) variablePressed:(NSString*) variable;
-(NSString*) callDescription;
+(NSString*) descriptionTop: (NSMutableArray*) stack;
-(id) undoVariable;
Could the error be caused because Im assigning a CGPoint.y value which should be float to a double? Also, since these are seperate MVC's I should avoid importing a file in one of them to the other right?
Lösung
You are making an instance method call. + (double)runProgram:(id)program usingVariableValues: (NSDictionary*) variableValues;
is a class method.
There are two potential fixes:
- Change the
+
to a-
. - Change
[self.graphingPoint runProgram:...]
to[[self.graphingPoint class] runProgram:...]
I have no idea how the code is structured, so it is not obvious which is more appropriate.