I want to setup a Method dispatch table and I am wondering if it is possible to create pointer to a method in Objective-C (like pointer to function in C). I tried to use some Objective-C runtime functions to dynamically switch methods but the problem is it will affect all instances.
As I am very new to Objective-C, an illustrated example would be highly appreciated.
Objective-C methods are called
selectors, and are represented by theSELdatatype. If your object inherits fromNSObject, you can tell it to perform a selector (i.e. call a method) like thus:This assumes you have a method defined such as:
Selectors are assigned to
SELdatatypes through the@selectorkeyword, which takes the name of the method you would like to keep. The name of the method is the method name stripped of all arguments. For example:Would be referenced as
@selector(doSomething:withParams:).