title: why the return value is nil and shows error?
body: <pre><code>func fetchDataForSQL(query : String)-&gt;NSDictionary{
  
      let url = URL(string: "###############################################")
      var jsonDBdata: NSDictionary!
      var request = URLRequest(url: url!)
      request.httpMethod = "POST"
      request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
      request.httpBody = query.data(using: String.Encoding.utf8)
      let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
          if (error != nil){
              print(error!)
  
          }
          else {
               jsonDBdata = try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
  
              print(jsonDBdata)
          }
      }.resume()
  
   return jsonDBdata
  }
  </code></pre>
  
  <p>Here if I print the <code>jsonDBdata</code> inside else part it is printing the value but when I return it, it shows the error "unexpectedly found nil while unwrapping an Optional value". Why can't I return here? What is its scope?</p>