ios - How to export method of inner class using JSExport -
i have 1 class methods , properties exported using jsexport. in normal cases, works well. if property type of inner class, can not accessed javascript.
following classes using:
person.swift
import foundation import javascriptcore @objc protocol personjavascritmethod : jsexport { var testproperty : outerclasspersonal.personal? { set } func sayhello(name1:string) } class person : nsobject, personjavascritmethod { var name : string! var testproperty:outerclasspersonal.personal? init(name:string) { testproperty = outerclasspersonal.personal() super.init() self.name = name } class func create(name : string) -> person { return person(name: name) } func sayhello(name1:string) { println("hello \(name) \(name1)") } }
personal.swift
import foundation import javascriptcore @objc protocol personaljavascritmethod : jsexport { func getnnn() } class outerclasspersonal:nsobject,jsexport{ class personal:nsobject,personaljavascritmethod { func getnnn(){ println("hip hip hurray") } } }
javascript.swift
import foundation import javascriptcore class javascript { let context = jscontext() func evaluatescript() { context.exceptionhandler = { context, exception in println("❌ error in javascript: \(exception) "); } var p1:person = person(name: "luitel") context.globalobject.setobject(p1, forkeyedsubscript: "person1") context.evaluatescript("person1.sayhello('sdf') \n ") var result = context.evaluatescript("person1.testproperty.getnnn() \n") println("\(result.tostring())") } }
when run evaluatescript() method, output following in console,
hello luitel sdf ❌ error in javascript: typeerror: undefined not function (evaluating 'person1.testproperty.getnnn()') undefined
i want access method getnnn() of personal class. here, if getnnn() method of outerclasspersonal class , outerclasspersonal implements personaljavascriptmethod, works properly.
the question is, how can access method of internal class "personal" javascript?
seems there no way exporting inner class functions javascript. moved inner class (personal) out , created independent class , worked.
Comments
Post a Comment