Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ah, when you added the "No visible @interface [...] declares the selector [...]", it is all clear.</p> <p>Consider a simpler form with just instance methods. You implement <code>-forwardInvocation:</code>, and then you have code like this:</p> <pre><code>[obj doSomething]; </code></pre> <p>Now, <code>MyObject</code> doesn't actually claim <code>doSomething</code> in its header, even though it will respond to it. So the compiler complains that this probably won't work. The fix for that is:</p> <pre><code>[(id)obj doSomething]; </code></pre> <p>When you declare something <code>id</code>, the compiler stops checking whether the target actually implements the selector. But it's also possible that <em>no</em> interface declares <code>doSomething</code>. Then the compiler is once again suspicious that it's probably a typo, and gives you a warning. And by "no interface," I mean "no interface that the compiler has access to." The compiler only has access to interfaces in this compile unit (i.e. the .m file and the headers it includes). So you need to make sure you include the header that defines this selector.</p> <p>Now for classes, you can't use <code>id</code>, but you should be able to use <code>Class</code> to achieve the same thing, such as:</p> <pre><code>[(Class)MyClass doSomethingClassy]; </code></pre> <p>If may want to see the <a href="https://github.com/rnapier/ios5ptl/blob/master/ch04/ObserverTrampoline/RNObserverManager.h" rel="nofollow">RNObserverManager</a> sample code from iOS:PTL Chapter 4 which demonstrates something similar.</p> <p>You should also definitely look at <code>forwardTargetForSelector:</code> that Ken Thomases references.</p> <hr> <p>You don't have to cast <code>sharedInstance</code> to <code>id</code>. Just change the signature, since you'll always want to use it that way:</p> <pre><code>+ (id)sharedInstance; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload