To keep this article reasonable in length, I will briefly cover the basic elements you need and then dive into some examples.
Our first step is to create a JSVirtualMachine instance along with a JSContext instance. If you don’t intend to use concurrent operations via threading, you can skip creating a JSVirtualMachine and just create a JSContext with an empty constructor so a JSVirtualMachine will be created for you. Otherwise, you should create and save a JSVirtualMachine instance and pass that as an argument when creating your JSContext instances.
Calling Functions and Evaluating Scripts
What we need to do next is find the path to the moment.js file, copy the contents of the file into a String, and inject it into our JSContext. See below for how you might accomplish that.
The last few things we need to do is to add the page.html file, which is loaded by the WKWebView in our ContactDrawable class.
To get our contact to display, I created a UIView and assigned it to XCPlaygroundPage.currentPage.liveView. Executing the Playground displays a simple list with randomly created “faked” contact details.
On a lighter note, I also wrote an article on why creating native apps is probably the best way to go in most of your mobile development endeavors. Read it and weigh in the discussion!
If your company only makes hybrid apps, you are going to lose in the end; it’s just a matter of time. Hybrid mobile…medium.com
I hope you found this post interesting. If you enjoyed it, recommend and like it!