title: Convert Data to String in Swift 3
body: <p>I am very new to Swift.</p>
  
  <p>I want to create something like API on Swift for my educational app.</p>
  
  <p>I have this code:</p>
  
  <pre><code>    static func getFilm(filmID: Int) -&gt; String {
  
      print("getFilm")
  
      let url = URL(string: "https://api.kinopoisk.cf/getFilm?filmID=\(filmID)")!
      var request = URLRequest(url: url)
  
      var returnData: String = ""
  
      let task = URLSession.shared.dataTask(with: request) { data, response, error in
          if var responseVar = response, var dataVar = data {
              print(responseVar)
              returnData = String(data: dataVar, encoding: .utf8)
          } else {
              print(error)
          }
      }
  
      task.resume()
  
      return returnData
  }
  </code></pre>
  
  <p>And I try to convert Data to String in this line: <code>returnData = String(data: dataVar, encoding: .utf8)</code></p>
  
  <p>Swift compiler gives me an error, and change this line to 
  <code>returnData = String(data: dataVar, encoding: .utf8)!</code> 
  , when I execute this line I get empty returnData variable.</p>
  
  <p>If I use basic example line 
  <code>print(String(data: data, encoding: .utf8))</code> 
  everything will be OK and I can see <code>data</code> in XCode console.</p>
  
  <p>So, how I can convert Data to String?</p>