Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to get rid of some of these warnings from my iPhone application. The one I get the most is when I have a void function and I call it using [self myFunction];. The warning is on the line where I call the function and it says: "Method '-myFunction' not found (return type defaults to 'id')." What do I need to do to fix this? Thanks

like image 386
Preston Avatar asked Mar 13 '11 23:03

Preston


1 Answers

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.

like image 199
mvds Avatar answered Oct 08 '22 06:10

mvds