ios - Importing JavaScript file into Swift file -
i trying execute javascript sdk within swift application. unable find file however. added file project using cmd + click project -> add files "projectname" -> add file , move projectname/ folder.
i still unable file , run inside jscontext
.
where going wrong?
here code (isok
used test case):
import foundation import javascriptcore public class wrapper { public var isok: bool var jscontext: jscontext init (pathtosdk: string) { let virtualmachine = jsvirtualmachine() self.jscontext = jscontext(virtualmachine: virtualmachine) if let sdkbundle = bundle.main.path(forresource: pathtosdk, oftype: "js") { let bundlestring = try! string(contentsoffile: sdkbundle) self.jscontext.evaluatescript(bundlestring) print("successfully initialised javascript context") self.isok = true } else { print("unable fetch sdk bundle @ path: \(pathtosdk)") self.isok = false } } }
i call in test:
func testisok() { let wrapper = wrapper(pathtosdk: "sdk").isok xctassertequal(wrapper, true) }
thanks , sorry if silly question, i'm brand new swift.
Comments
Post a Comment