Embed Javascript code into Swift


Hello All,

Just starting the course. So far, so good.

One simple thing I’m trying to do is embed some JavaScript code into SWIFT. What is the best way to do this?

The code I’m looking to embed is:

script type=“text/javascript”*
noscript> To get the WTI oil price, please enable Javascript.*


You can read JavaScript in a webview and return results, you cannot embed it, as JavaScript is a Web language that is interpreted by a browser.


OK, I think I’m almost there. I’m seeing the following error now…

2015-12-18 09:26:16.655 UIWebView Example[2422:150030] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.

How do I configure Info.plist?



in your app on the left in Xcode right click on the plist -> show in finder
Edit the plist in any text editing program and add this key to the top of the structure:


Please note how everything is structured ( if you don’t put it correctly you’ll get a warning in Xcode )

However this will make your app unsafe and there is a chance Apple will not approve it.

This is how it should look after you change it:


Great answer! Thanks!