0

I'm trying to write a function that runs an evaluateJavaScript, waits for the result and returns it in Swift as a func return param. Something like this:

func getCurrentTime() -> CGFloat{
  var currentTime:CGFloat = 0.0

  webView.evaluateJavaScript("window.clock.getCurrentTime()") { (result, error) in
    guard error == nil else {
            return
        }
    currentTime = result    
  }

  return currentTime
}

Since this function is exposed in an API I can't have a self.currentTime var to be set within the closure. I think it would be easier for anyone who uses the API to have this method return the value

Mihai Fischer
  • 329
  • 2
  • 11

0 Answers0