It’s certainly possible, but probably more hassle than it’s worth.
Specifically, Swift supports compiling to WebAssembly (Wasm) [1] and you could then run the Wasm instructions yourself. However, this is much more difficult than the equivalent path with JavaScriptCore because:
-
JavaScriptCore can interpret JavaScript directly. In Swift you’d have to include a copy of the Swift compiler within your app.
-
Additionally, there’s no built-in Wasm runtime, so you’d have to write or acquire one of those.
Of these, the second point is less of an issue. Wasm runtimes are relatively small and easy to maintain. Indeed, there’s a default one featured on the Swift website [2].
The first point, however, is much more complex. The Swift compiler is big and complicated, and successfully embedding it in an iOS app would not be trivial.
Finally, there’s the App Review side of this. I don’t work for App Review, and thus can’t make definitive statements on their behalf. However, the App Review Guidelines do place restrictions on downloadable code, so I encourage you to read those.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] See Swift.org > Getting Started with Swift SDKs for WebAssembly.
[2] WasmKit