Skip to content
Advertisement

How I can return result of js or any function to the screen of iPhone? by ContentView

JavaScript

(Sorry, I’m beginner and come to swift even not from js, but from python! So it’s incredibly new for me. But js more understandable for me from python.)

enter image description here

Advertisement

Answer

Here’s the simplest version. In this version, it basically uses your original pattern where doJS returns a value. The disadvantage to this version is that doJS will get called every time the view renders.

JavaScript

And here’s a slightly different version. In this version, Cube is an ObservableObject with a @Published value that stores the result. It will only get called once in onAppear.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement