objective-c warning ‘class’ may not respond to ‘method’

17 02 2009

This is a very interesting error message, you may want to look at the order of the method you are calling, and the code that causes the warning message. 
-(void) aMainMethod{
 [self testMethod] //call the method, warning occurs here
 ....
}
//here's the method you are calling
-(void) testMethod{
  NSLog(@"test");


If  your method is at somewhere after the code you call it (if it’s like above), move it so that it’s before the code (like the code below), and the warning should go away. Even with the warning, you should still be able to compile and run without any problem. 

//here's the method you are calling
-(void) testMethod{
NSLog(@"test");
}
-(void) aMainMethod{
[self testMethod] //no warning
....
}

Here’s an article about this with more details.


Actions

Information

8 responses

29 03 2009
RaiulBaztepo

Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language ;)
See you!
Your, Raiul Baztepo

29 03 2009
Emily

Glad I can help ^__^

Cheers
Emily

7 06 2009
vladino

Thanks a lot! Really helpful, I finally got rid of those silly warnings ;)

25 08 2009
Ben

If you would have declared the function in the header of the file (the .h file) then it would not matter where the function body exists.

Doing that will fix the errors as well. (Also the programming standard to declaring functions in C and Objective-C).

6 10 2009
Baris

Well, that would make your interface unnecessarily bloated. You wouldn’t want to add internal methods to your interface.

14 09 2009
John

Thanks, this helped.

FWIW, the problem appears to exist at the file level as well: class #0 in the file order calling a ‘-method’ from class #1 in the file order caused this problem for me. Reordering the files fixed it.

14 09 2009
peter

thank you!
my third day in objectiveC.
its annoying structure and too big file size.

they need actionscript for iphone. its better 1million times.

28 10 2009

Leave a comment