How do I fix this warning: "Method not found (return type defaults to 'id')" How do I fix this warning: "Method not found (return type defaults to 'id')" objective-c objective-c

How do I fix this warning: "Method not found (return type defaults to 'id')"


Declare the function in your header file, like so:

 -(void)myFunction;

or

 -(NSString*)myFunction; -(id)myFunction; -(NSInteger)myFunction; -(BOOL)myFunction;

etc etc.

This is of more importance than just silencing the compiler: if the return type of a function is not a pointer (id or anything*), especially when it doesn't have the same size, you can get really odd and hard to find bugs.

E.g. if a function returns a CGRect struct, and the compiler assumes id (as the warning says), really weird things will happen.


You need to define that function in your header file (.h) (if it should be visible to other classes), or in your implementation file (.m) if it is private to your class.

For example, if you use a method:

-(void)myFunction {    // do something}

For a "private" function, add this at the top of your .m file; before the @implementation MyCoolClass line.

@interface MyCoolClass()  // <--- no 'category name' hides methods just for this file-(void)myFunction;     // <--- add the method here-(void)myOtherFunction;-(void)doSomeCoolThingWithThisString:(NSString *)firstName;@end

OR if you want to call the method from other files, add it in your .h file, inside the 'interface' section; after all your properties, and before the @end.

Good luck!


You need to import the .h file that contains yours methods