maximus
maximus

Reputation: 2437

Create functions at runtime with swift

How can I create a function or method at runtime using Swift? Is there an equivalent command like eval? I would like to be able to do something like:

eval("func x(){ println();}")

Thanks in advance!

Upvotes: 5

Views: 493

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187134

Given that it's not an interpreted language, I don't think you can. C for instance, has no eval since the C compiler is not part of the compiled binary.

But I'm sure there are lots of other (read: better) ways to accomplish that goal that you think you need eval for. Whatever that is...

Upvotes: 7

Related Questions