title: Lose value of singleton
body: <p>I am making a call to a web-service and get a token back. I have tried different ways to safe this in globals variables and now tried a singleton. When I print the value immediately after I have set it I get the value but once I am out of the web service <code>URLSession.shared.dataTask</code> call and cll the resume the value in the singleton is gone. Below is my code, please note I am only doing swift now for a week :)</p>
  
  <pre><code>request.httpBody = postString.data(using: .utf8) 
  
      let task = URLSession.shared.dataTask(with: request) { data ,response, error in
          guard let data = data, error == nil else {                                                 // check for fundamental networking error
              print("error=(error)")
              return
          }
  
          if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {           // check for http errors
              print("statusCode should be 200, but is \(httpStatus.statusCode)")
              print("response = (response)")
          }
  
          // Get rid of ekstra escape chars
          let responseString = String(data: data, encoding: .utf8)
          let newString = responseString?.replacingOccurrences(of: "\\", with: "")
          let newString2 = newString?.replacingOccurrences(of: "\"{", with: "{")
          let newString3 = newString2?.replacingOccurrences(of: "}\"", with: "}")
          let newdata = newString3?.data(using: .utf8)!
  
          do {
              let json = try JSONSerialization.jsonObject(with: newdata!, options: .allowFragments) as! [String:Any]
              Singleton.sharedInstance.setToken(Token: (json["SessionToken"] as? String)! )
              print(Singleton.sharedInstance.getToken()) // VALUE CORRECT
  
          } catch let error as NSError {
              print(error)
          }
  
          print(Singleton.sharedInstance.getToken()) // STILL GET THE CORRECT VALUE
      }
      task.resume()
  
      print(Singleton.sharedInstance.getToken()) // THE VALUE IS NOW NIL
  
  
  class Singleton {
  static let sharedInstance = Singleton()
  
  var rToken:String?
  
  func setToken( Token:String){
      let lToken = Token
      rToken = lToken
  }
  
  func getToken() -&gt; String {
  
      if self.rToken != nil {
          return self.rToken!
      }
  
      return "0"
  }
  </code></pre>
  
  <p>}</p>