title: DispatchQueue Main async reference problem. (Reference gone)
body: <p>I have a function for getting user session. I successfully get the session. But inside the DispatchQueue i lose task object (task:AWSTask&lt; AWSCognitoIdentityUserSession >). </p>
  
  <p>Before DispatchQueue it is not null but in the dispatch DispatchQueue it is null. Some how i am losing the reference. </p>
  
  <p>What is the best way to get and object reference from outside of the DispatchQueue. (I dont want to create a general variable in the class.)
  <strong>BTW this is not happening all the time.</strong></p>
  
  <pre><code>var pool:AWSCognitoIdentityUserPool
  
  override init(){
      pool = AWSCognitoIdentityUserPool(forKey: "UserPool")
      super.init()
  }
  
  func getUserPool() -&gt; AWSCognitoIdentityUserPool {
      return pool
  }
  
  func getUserSession(completition: @escaping () -&gt; Void)
  {
      let user = pool.currentUser()!
      let task = user.getSession()
             task.continueWith{ (task:AWSTask&lt;AWSCognitoIdentityUserSession&gt;) in
              {
                  DispatchQueue.main.async
                  {
                      if(task.result != nil &amp;&amp; task.error == nil)
                      {
                          /*
                           There are some calculations here
  
                           */
  
                          completition()
                      }
                  }
              }
      }
  }
  </code></pre>