Re: Abstracting a group of commonly named Selectors
Jeff Laing
In the designated initialise of your Parser class, you can use class_addMethod to add whatever you like to your instance's class. https://developer.apple.com/documentation/objectivec/1418901-class_addmethod?language=objc The method implementation gets called with the selector as its second argument and you can cut the string up at runtime to then call your Parse. Here's a snippet from an app I did in the past that wanted to dynamically adjust to any entries that were added to a popup menu in Interface Builder. It iterates over the popup, and for every entry present, looks for then adds a dynamic method called _popup.
The implementation of the method gets the name of the selector using set_getName, then punts across to the actual code.
Extracting your specific token from the message is just name+. This example is using (void) but it should work just fine - you aren't using the "no such method" path, you are just binding the method really late in the compile/link/run process... |
|