In obj-c, how can I call
[myClass myString];
where myString = @"myMethod";
Which should be the equivalent of [myClass myMethod];
Not sure if this kind of meta language manipulation is possible.
[myClass performSelector: NSSelectorFromString(myString)];
Docs:
NSString
into a selector (type SEL
)[myClass class]
returns the metaclass, class methods are called on the metaclass. E.g.
[NSString someClassMethod];
NSString *instanceOfString = @"some string instance";
[[instanceOfString class] someClassMethod];
EDIT: I misread the question. Use NSSelectorFromString
to get a SEL from an NSString. That's documented in Apple's Foundation Functions Reference where you'll also see NSClassFromString
, NSStringFromClass
, NSStringFromSelector
, NSStringFromProtocol
and NSProtocolFromString
amongst others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With