Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create functions at runtime with swift

Tags:

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!

like image 914
maximus Avatar asked Jun 04 '14 18:06

maximus


1 Answers

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...

like image 189
Alex Wayne Avatar answered Oct 05 '22 21:10

Alex Wayne