I'm getting this error and I know this problem has been addressed on here before by people not adding the return -> to the function. I do not understand why this is still giving me error.
Unexpected non-void return value in void function
I'm trying to return a String called message.
func ParseIt(proURL: String, startStr: String, stopStr: String) -> String {
let url = URL(string: "https://www.siteimfetchingfrom.com/827444000973")
let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
if error != nil {
print(error)
} else {
let htmlContent = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
//print(htmlContent)
// Get all Product Info
//var proName = "id=\"productName\" value=\""
if let contentArray = htmlContent?.components(separatedBy: startStr) {
//print(contentArray)
if contentArray.count > 0 {
//proName = "\" required"
let newContentArray = contentArray[1].components(separatedBy: stopStr)
if newContentArray.count > 0 {
let message = newContentArray[0]
//print(newContentArray)
print(newContentArray[0])
return message // Error happens Here
}
}
}
}
}
task.resume()
}