Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jschulbach

macrumors newbie
Original poster
Jun 29, 2010
15
0
I've got a singleton class that I'm calling a method on and get the "'x' may not respond to 'y'" warning. The method works fine, the .h for the singleton class is imported at the top of my implementation file where I'm using it. When searching online I get a lot of people talking about the method being placed above the code where the method is called. In my case the method is in another file that is included at the top of the file where it is called. I also saw some suggestions about reordering the class file list but the singleton class is the first in my list so that shouldn't be the issue. What else might cause this warning?
 

jschulbach

macrumors newbie
Original poster
Jun 29, 2010
15
0
I figured it out. I'm using a class someone else wrote and the method that was being called wasn't declared in the .h for the singleton class. I'm pretty new so I didn't think to check for that. Are the methods not listed in the .h file generally methods intended to only be used within the class itself?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Are the methods not listed in the .h file generally methods intended to only be used within the class itself?
Correct. And if they're not listed in the .h file, then they can only be called from within the class itself. You might also run into the "may not respond to" warning if the compiler has not seen the method defined before encountering a usage of it. Such a warning can be avoided by either moving the method definition before its first use or via the Objective-C version of private methods: creating a category on the class itself that declares the method.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.