I want to refer json2html.js & jquery.json2html.js into my Swift 3.0 project. While I try invoking the json2html.transform using the JavaScriptCore class (in swift), it's returning undefined. Please refer to below code screenshot.
func loadJavascript()
{
let jsSource = jsfile1+jsfile2
let data = try!String(contentsOfFile:Bundle.main.path(forResource:"data", ofType: "json")!)
let transform = try!String(contentsOfFile:Bundle.main.path(forResource:"transform", ofType: "json")!)
let context = JSContext()
let fun = context?.evaluateScript(jsSource)
let Func = fun?.objectForKeyedSubscript("json2html.transform")
let Call = (Func?.call(withArguments: [data,transform]))
/
webView.loadHTMLString((Call?.toString())!, baseURL: nil)
}
- jsfile1 & jsfile2 are the 2 JS file contents (JS and jQuery) for JSON2HTML converted to String
- I've saved the code for data and transform in 2 separate files(which work well without Swift). Those 2 files are data and transform (I have saved transform data inside JSON-anyhow will be converted to String)
Normal JS functions work fine while I tried it in the same way. Could anyone please help me out?
Also, is there any pre-built JSON2HTML library/framework built for Swift that could be integrated via CocoaPods into swift.
Awaiting for reply! Thanks a lot in advance.