-6

How can I get the string value in Optional() in swift, which is followed by nil?any other proper way to use this evaluateJavaScript() and get the callback value?

    webView.evaluateJavaScript("(function() { return 'this'; })();", 
      completionHandler: {
        result in
        //Handle your variable
        print(result)//(Optional(this), nil)
    })

1 Answers1

-1

Use if let to parse the optional value:

if let value = result {
    print(value)
}
Rashwan L
  • 38,237
  • 7
  • 103
  • 107
  • webView.evaluateJavaScript("(function() { return 'this'; })();", completionHandler: { result in //Handle your variable if let value = result { print(value) } }) I get error, Initializer for conditional binding must have optional type – user3173952 Jun 19 '17 at 16:36
  • 1
    Don't answer duplicate questions. Instead, vote to close them as dupes. – JAL Jun 19 '17 at 16:57