I’m doing some work with dynamic programming in Objective-C and I’ve read through the Objective-C Runtime Programming Guide front to back and been able to do most of what I need, but the one thing I haven’t figured out is how to call a method dynamically provided I have a string representation of it.
Essentially I dynamically do a property lookup to see if my object has a property that matches from a list using class_copyPropertyList and then loop through and match these via an NSMutableDictionary that is populated from a plist file. When a match is found I want to execute the property. I have no way of knowing ahead of time what matches could possibly exist as this is a lib that will be packaged into many different apps.
Use
NSSelectorFromStringto create aSELfrom anNSString. Then you can execute it using one of theperformSelectormethods.Setting a property dynamically:
Getting a property dynamically:
For more complicated methods you can use
NSInvocationandNSMethodSignature: