'may no respond to' warning

Discussion in 'iOS Programming' started by jschulbach, Jul 30, 2010.

  1. jschulbach macrumors newbie

    Jun 29, 2010
    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?
  2. jschulbach thread starter macrumors newbie

    Jun 29, 2010
    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?
  3. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    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.

Share This Page