Search code examples
iosobjective-cios6xcode4.5

No visible @interface for 'class' declares the select 'method' when calling super


I have the following code,

In .h file:

@interface MyBaseClass : NSObject
{
    - (void)myMethod;
}

In .m file:

@implementation MyClass2000 : MyBaseClass
{
    - (void) myMethod
    {
        //Does something interesting here
        myData[0] = 0;
        myData[1] = 1;
    }
}

Later I created a class that extends "MyClass2000" and is called "MyClass2001"

.h file:

#import "MyClass2000.h"

@interface MyClass2001 : MyClass2000
@end

.m file:

@implementation MyClass2001 : MyClass2000
{
}

This class is exactly the same as "MyClass2000" (but I specifically need to keep them in separate classes, and one extending the other. I also need a "MyClass2002 class", which in this case will need to update only 1 of the indexes, so I tried to call [super myMethod] as follows:

The next class extends "MyClass2001"

.h file:

#import "MyClass2001.h"

@interface MyClass2002 : MyClass2001
@end

.m file:

@implementation MyClass2002 : MyClass2001
{
    - (void) myMethod
    {
        [super myMethod];

        //Only update one value
        myData[1] = 1;
    }
}

On that line I'm getting: No visible @interface for 'MyClass2001' declares the selector 'myMethod'.

Any tips on how to get this to work?

Thanks!


Solution

  • That isn't how you declare a method in Objective-C. In your interface, you declare the method like this:

    @interface MyClass2000 : MyBaseClass {
        NSString *someVariableDeclaration;
    }
    
    - (void) myMethod;
    
    @end
    

    And then you implement the function in your .m like this:

    @implementation MyClass2000 {
        NSString * someDifferentVariableDeclaration;
    }
     - (void) myMethod
    {
        //Does something interesting here
        myData[0] = 0;  
        myData[1] = 1;
    }
    @end