I know that I'm not the first one to ask this but I can't solve the problem. I'm trying to take a piece of string from HTML using evaluateJavaScript
in Xcode with Swift 3 and the piece of text is called value
inside the completion handler, so I did like this:
var userName = String()
func takeData() {
webView.evaluateJavaScript("document.querySelectorAll('.name')[0].innerHTML") { (value, error) in
if let valueName = value as? String {
self.userName = valueName
}
print(value)
print(error)
}
}
print(" The name is : \(self.userName)")
The problem is that the console just prints: The name is ()