Saturn
Saturn

Reputation: 18149

Evaluating strings in Objective-C

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?

Upvotes: 0

Views: 485

Answers (1)

JeremyP
JeremyP

Reputation: 86661

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.

Upvotes: 3

Related Questions