title: swift: Retrieving images from "Parse"
body: <p>Im new in Parse(parse.com). I have such kind of table in parse.com:
  <a href="https://i.stack.imgur.com/78Trn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/78Trn.png" alt="enter image description here"></a></p>
  
  <p>And I wanna retrieve these 3 images and put are in table view row. And here is my code:</p>
  
  <pre><code>class LeaguesTableViewController: UITableViewController {
  
      var leagues = [PFObject]() {
          didSet {
              tableView.reloadData()
          }
      }
  
      var leaguesImage = [NSData]() {
          didSet {
              tableView.reloadData()
          }
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          loadData()
          tableView.registerClass(LeaguesTableViewCell.self, forCellReuseIdentifier: "ReusableCell")   
      }
  
      // MARK: - Table view data source
  
      override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          return 1
      }
  
      override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return leagues.count
      }
  
      override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
          return 160
      }
  
      override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCellWithIdentifier("ReusableCell", forIndexPath: indexPath) as! LeaguesTableViewCell
  
          cell.leagueImage.image = UIImage(data: leaguesImage[indexPath.row])
          cell.leagueNameLabel.text = leagues[indexPath.row]["name"] as? String
  
          return cell
          }
  
      // MARK: Parse
  
      func loadData() {
  
          let query = PFQuery(className: "Leagues")
          query.findObjectsInBackgroundWithBlock { (objects, error) in
              if( objects != nil &amp;&amp; error == nil) {
  
                  // List of leagues
                  for i in objects! {
                      self.leagues.append(i)
  
                      // Retrieve images
                      let imageFile = i["image"] as? PFFile
                      imageFile!.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -&gt; Void in
                          if error == nil {
                              if let imageData = imageData {
                                  self.leaguesImage.append(imageData)
  
                              }
                          }
                      }
                  }
  
              } else if error != nil {
                  print("Error is: \(error)")
              }
          }
      }
  }
  </code></pre>
  
  <p>Here is my code and from my point of view is everything is ok. But I have error: Index out of the range. My leaguesImages array is empty. Thank you.</p>