I created a function to get URL from API, and return URL string as the result. However, Xcode gives me this error message:
Unexpected non-void return value in void function
Does anyone know why this happens?
func getURL(name: String) -> String {
let headers: HTTPHeaders = [
"Cookie": cookie
"Accept": "application/json"
]
let url = "https://api.google.com/" + name
Alamofire.request(url, headers: headers).responseJSON {response in
if((response.result.value) != nil) {
let swiftyJsonVar = JSON(response.result.value!)
print(swiftyJsonVar)
let videoUrl = swiftyJsonVar["videoUrl"].stringValue
print("videoUrl is " + videoUrl)
return (videoUrl) // error happens here
}
}
}