As I understand it, an unrealized method is solved as follows:
- resolveInstanceMethod: / resolveClassMethod: gets the opportunity to implement the method
- forwardingTargetForSelector: gets the option to send to the delegate
- forwardInvocation: gets the ability to process the method as it sees fit.
Where is this three-step process determined? I would like to handle this myself, since NSInvocation may be too heavy for my needs. I had a signal from a runtime source and can't see anything.
It looks like the old runtime will cause a redirect: args: on the receiver to do this, but it seems to have gone away with the new one. I assume that the process should be determined by the framework, and not the runtime, since it would be strange if the runtime depended on Cocoa to the extent that NSInvocation was required to process messages. Perhaps this is an undocumented method called in NSObject / NSProxy?
Edit:
It looks like the runtime declares, but never defines, a C function that is called when objc_msgSend cannot find an implementation:
id objc_msgForward(id object,SEL message,...);
I do not work for Apple, so I do not know how Foundation implements this, but at least in the case of Cocotron, they use:
id objc_msgForward(id object,SEL message,...) { Class class=object->isa; struct objc_method *method; void *arguments=&object; if((method=class_getInstanceMethod(class,@selector(forwardSelector:arguments:)))!=NULL) return method->method_imp(object,@selector(forwardSelector:arguments:),message,arguments); else { OBJCRaiseException("OBJCDoesNotRecognizeSelector","%c[%s %s(%d)]", class_isMetaClass(class) ? '+' : '-', class->name,sel_getName(message),message); return nil; } }
adding forwardSelector:arguments: method doesn't seem to work, so I assume this is Cocotron specific. Does anyone know what objc_msgForward does in Foundation?
objective-c objective-c-runtime cocoa
Chris devereux
source share