Reputation: 819
I need to do a thing like this:
id myFunction = aMethodDeclaredInMyClass;
[self myFunction]
any help is appreciated!
Upvotes: 2
Views: 5258
Reputation: 3358
My guess is you want;
[self performSelector:@selector(aMethodDeclaredInMyClass)]
Read the docs on dynamic dispatch;
Upvotes: 3
Reputation: 96967
Also see objc_msgSend()
. You'd set up a SEL
selector variable.
Upvotes: 0
Reputation: 97962
If you know the method in advance:
[self performSelector:@selector(myMethod) withObject:nil];
If you don't know the method name in advance:
SEL selector = NSSelectorFromString(someSelectorStringYoureGiven);
[self performSelector:selector withObject:nil];
Both these examples assume your function accepts no arguments, nor requires execution on a different thread, nor requires delayed execution. There are many variants for all combinations of those conditions (and NSInvocation for even more complex cases). Search performSelector
in xcode's documentation to see all the variants.
Upvotes: 5