Reputation: 21
I am getting an issue when calling a method of return type -(void)
in same class
Issue is:Instance method - someMethodName not found (return type defaults to 'id')
Upvotes: 0
Views: 84
Reputation: 11920
The problem is that Xcode can't find a declaration for the method. In most recent version of Xcode you don't need to provide a declaration for a method if the implementation is in the same .m
that you are calling it from. e.g.:
//ExampleClass.m
@implementation ExampleClass
-(void)aMethod {
[self anotherMethod]; //Xcode can see anotherMethod so doesn't need a declaration.
}
-(void)anotherMethod {
//...
}
@end
However in earlier version of Xcode you would need to provide a declaration. You can do this in the @interface
in .h
file:
//example.h
@interface ExampleClass : NSObject
-(void)anotherMethod;
@end
The problem with putting the declaration in the .h
is that all other class can see the method, which may cause problems. To get around this you can declare a class continuation within the .m
:
//ExampleClass.m
@interface ExampleClass ()
-(void)anotherMethod;
@end
@implementation ExampleClass
//...
@end
Upvotes: 0