title: What determines the process by which unimplemented methods are resolved?
body: <p>As I understand it, an unimplemented method gets resolved in the following way:</p>
  
  <ol>
  <li>resolveInstanceMethod: / resolveClassMethod: gets a chance to implement the method</li>
  <li>forwardingTargetForSelector: gets a chance to forward to a delegate</li>
  <li>forwardInvocation: gets a chance to handle the method as it sees fit.</li>
  </ol>
  
  <p>Where is this three-step process defined? I'd like to handle it myself as NSInvocation might be too heavyweight for my needs. I've had a poke around the runtime source and can't really see anything.</p>
  
  <p>It looks like the old runtime would call forward:args: on the receiver, to do this but that seems to have gone from the new one. I'm guessing that the process must be defined by the framework rather than the runtime, since it'd be strange if the runtime depended on Cocoa to the extent of requiring NSInvocation to handle messages. Is it maybe an undocumented method that gets called on NSObject / NSProxy?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>It looks like the runtime declares, but never defines, a C function which is called when objc_msgSend can't find an implementation:</p>
  
  <p><code>id objc_msgForward(id object,SEL message,...);</code></p>
  
  <p>I don't work for Apple, so I don't know how Foundation implements this, but at least in the case of Cocotron, they use:</p>
  
  <pre><code>id objc_msgForward(id object,SEL message,...)
  {
     Class       class=object-&gt;isa;
     struct objc_method *method;
     void       *arguments=&amp;object;
  
     if((method=class_getInstanceMethod(class,@selector(forwardSelector:arguments:)))!=NULL)
          return method-&gt;method_imp(object,@selector(forwardSelector:arguments:),message,arguments);
     else
     {
         OBJCRaiseException("OBJCDoesNotRecognizeSelector","%c[%s %s(%d)]", class_isMetaClass(class) ? '+' : '-', class-&gt;name,sel_getName(message),message);
         return nil;
     }
  }
  </code></pre>
  
  <p>adding a <code>forwardSelector:arguments:</code> method doesn't seem to work, so I'm guessing this is specific to Cocotron. Anyone know what <code>objc_msgForward</code> does in Foundation?</p>