I have a function that is called by javascript with JavascriptCore. Now inside that function I have to evaluate a javascript again under a certain condition. This should call the same function.
let My_JS_Function: @convention(block) ( String, String, String ) -> ( ) = {
thing_1, thing_2, thing_3
in
let my_Condition = true
if my_Condition {
let c = JSContext()
// compiling error: "Variable used within its own initial value"
Context.setObject(unsafeBitCast(My_JS_Function, AnyObject.self), forKeyedSubscript: "My_JS_Function")
c.evaluateScript("My_JS_Function("value 1","value 2","value 3");")
}
}
Now XCode tells me:
Variable used within its own initial value
Does anybody know wheather there's a way how to solve this problem? Maybe a way to write the My_JS_Function as a function and not like here as a variable?
I could fix the problem with avoiding having functions as properties. Therefor I put the functionality in an extra class and used JSExport.
One example for how it can be done with JSExport can be found here.