Reputation: 1535
Lets say I download some text from webservice contain objective-c code, is there any way to make it selector?
EDIT: I edited my title, what I mean is building a function from downloaded string at runtime.
Upvotes: 2
Views: 110
Reputation: 2497
It sounds like you want load additional functionalitiy from webservices? Do you have just functions/selectors names in that text or bodies/implementations also? In latter case you can't run non-compiled code, you should first compile it and then, dependent whether platform enables you to load binaries at the runtime - you can try to run it.
If it's just method names -
NSSelectorFromString()
Upvotes: 0
Reputation: 1840
uhh, what do you mean obj-c code...
Are you downloading a class/code that you need to compile at runtime?
or you already have these methods in your implementation, the service only tells you what methods to call?
If the latter is correct, then you can use this:
SEL aSelector = NSSelectorFromString(@"methodName")
beware that if this method contains parameters you will a string like this:
SEL aSelector = NSSelectorFromString(@"methodNameWithParam:anotherParam:")
If the former is correct, welcome to the Objective-c runtime, It is technically possible but i do not know the apple guidelines will take too kindly to you downloading and patching code at runtime.
hope it helps.
Upvotes: 4
Reputation: 4490
You can use the NSSelectorFromString()
function to get a SEL
(selector) from an NSString
object.
Upvotes: 0