0

In Ruby, I was able to execute strings as code like

eval("print 5")

Is it possible to do exactly the same in Objective-C?

1

1 Answer 1

3

No. Objective-C is a compiled language. To evaluate strings like that, there would have to be a compiler embedded in the runtime, and there isn't.

There is a limited form of executing strings using methods like-performSelector and valueForKey: and NSInvocation.

Sign up to request clarification or add additional context in comments.

4 Comments

So, if i want to make an app for compiling co code from iOS app, what would be possible best way ? Already there are many apps on appstore.
You either have to include an interpreter or a compiler in your app. Or you can probably leverage the Webkit Javascript interpreter, if you don't mind Javascript.
So, can i compile my C code with a local JS file (which return eval result) from app ? or i have to use it from server ? please, elaborate or give me some link to get help. I am going to dev an app regarding this function.
@JamshedAlam It would be better if you authored a question rather than ask in the comments here, then more people will see it and answers can be written more easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.