I need to return parseResult
(String) from the closure as the function result. How can i do it in Swift? The parseResult
value is not not within the range of function.
import Kanna
class Parse {
class func parseFromWeb(parseUrl: String, xpath: String) {
let url = URL(string: parseUrl)!
let task = URLSession.shared.dataTask(with: url, completionHandler: { ( data , response , error ) in
DispatchQueue.main.async{
var serverString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
if let doc = Kanna.HTML(html: String(describing: serverString), encoding: String.Encoding.utf8) {
for parseResult in doc.xpath(xpath) {
print(parseResult)
}
}
}
})
task.resume()
print("task.resume()")
}
}