UIWebView's - stringByEvaluatingJavaScript(from:) is synchronously returning a String? value.
The WKWebView equivalent evaluateJavaScript(_:completionHandler:) works with a complitionHandler.
I'm working with legacy code and I have stringByEvaluatingJavaScript(from:) affecting thousands of lines in the code and can be found everywhere and in a lot of functions that return values (not using blocks).
very simple example -
@discardableResult func js(_ script: String) -> String? {
let callback = self.stringByEvaluatingJavaScript(from: script)
if callback!.isEmpty { return nil }
return callback
}
now that I'm changing to evaluateJavaScript(_:completionHandler:) I will need the js(script:) method to be handled with a block, and methods that use that method needs to change and so on...
I think that in order to fix this without changing all my code I need evaluateJavaScript(_:completionHandler:) to synchronously return String?.
Does anybody know how this can be achieved? or maybe have a different solution?