Design Element
Comment on "Dynamic Objective-C with NSInvocation"
by Scott Ahten — May 13
Notice that Scott's example doesn't indicate what class is actually implementing the method. Due to the dynamic nature of Objective-C, the object passed to setTarget: could be any object, not just self or a object of a particular class.

Instances of Java's Method class represent a "fully qualified" method. That is, the instance is a reference to both the method signature and the class that implements it. As such, you can't successfully invoke the method on an instance just because it has a method with the same signature. The target must be an instance of the same class as well.

Selectors in Objective-C represent "messages" that can be sent to any object, regardless of what class they are instantiated from. As long as the target object responds to the selector, the invocation is successful. If the target object does not respond to the selector, an exception is thrown or the target can optional forward the message on to another object.
Back to "Dynamic Objective-C with NSInvocation"
Design Element

Copyright © Scott Stevenson 2004-2015