title: Setting label text after completing block Swift
body: <p>I want to set user name to a label because my block ("findObjectsInBackgroundWithBlock") is taking time to complete and <strong>label.text</strong> sets <strong>nil</strong> . </p>
  
  <p>how to set label text after completing the block??</p>
  
  <pre><code>class test {         
  
  var userName: String? // variable to access user name returned by block        
  private func loadData() {      
  
  getCurrentUser()         
  lblUserName.text = userName       
  
  }    
  
  }
  </code></pre>
  
  <p>This is the block where i am getting user data from Parse.</p>
  
  <pre><code>private func getCurrentUser() {         
  
          if PFUser.currentUser() != nil { 
  
              currentUser = PFUser.currentUser()?.username    
              let query = PFQuery(className: "_User")    
              query.whereKey("username", equalTo: currentUser!)    
              query.findObjectsInBackgroundWithBlock { (currentUsers, error) -&gt; Void in 
                  if error == nil {     
                      for user in currentUsers! {     
                         userName = user["name"] as? String      
                      }   
                  }
              }
          }
      }
  </code></pre>