title: Why does Unexpected non-void return value in void function happen?
body: <p>I created a function to get URL from API, and return URL string as the result. However, Xcode gives me this error message: </p>
  
  <blockquote>
    <p>Unexpected non-void return value in void function</p>
  </blockquote>
  
  <p>Does anyone know why this happens?</p>
  
  <pre><code>func getURL(name: String) -&gt; 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
              }
          }
  }
  </code></pre>