-4

I've seen a learning app doing this.

It runs the swift code inside the iOS app. so I downloaded the swift's source code and now I don't know what should I do next.

it's completely different from something like bridge ... the user must write the code ... not me ... for example in python we can use it's library to run a command given as string:

#include <Python.h>

int main(int argc, char *argv[]) {
  Py_SetProgramName(argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}

now I'm searching for something like: SwiftRun_SimpleString("print(\"Hello!\")");

shallowThought
  • 18,342
  • 7
  • 61
  • 106
  • please leave a comment why -1 ... or at least mark it as something ... thanks – Ebrahim Tahernejad Nov 07 '16 at 18:05
  • Possible duplicate of [How to import Swift code to Objective-C](http://stackoverflow.com/questions/24102104/how-to-import-swift-code-to-objective-c) – Robotic Cat Nov 07 '16 at 18:05
  • thats not right my friend ... I want to compile the swift code INSIDE the running app on ios ... user writes the code ... not me ... thanks for understanding – Ebrahim Tahernejad Nov 07 '16 at 18:07
  • I did not downvote, but you might want to goolge something like "use swift code in objective c" before asking. – shallowThought Nov 07 '16 at 18:07
  • @shallowThought and that will go straight to the questions that they downvoted me for ... but my question is completely different – Ebrahim Tahernejad Nov 07 '16 at 18:09
  • 1
    Your question is down voted because most people skim read questions and don't take the time to actually read what a question is really asking. They probably only read your title and nothing else. And so people think your question is how to combine swift code in objective c. To stop these lazy morons from assuming they know what your question is about without reading it, in the future you need to make it more specific in your title what the question is about, for example by adding words saying its for code entered by the user at run time for example. – Gruntcakes Nov 07 '16 at 19:16
  • @Essenceofchickens Thanks ... I will surely do that from now on ... but ... I'm banned from asking questions already :)) – Ebrahim Tahernejad Nov 09 '16 at 17:22

1 Answers1

2

What you are asking is how to run or interpret Swift code that is provided at run time, like the Swift command-line REPL or the iPad's Swift Playgrounds app. The full answer is really much too complicated for stackoverflow.

You'll need to use the Swift compiler source code to do this. Start by looking at swift-lldb (the version of the llvm project's debugger with Swift support), which does what you're describing.

rob mayoff
  • 358,182
  • 62
  • 756
  • 811