title: Load images for collection view in background thread
body: <p>So I have a collection view in which I'm populating 141 images into it, but the problem I'm having is when scrolling through the view, it's not very smooth. I've already tried using low res images for the cells (which helped slightly) and decreasing the swipe speed (or should I say increasing the deceleration when scrolling). </p>
  
  <p>So I figured my next step would be to try loading the cells on a background thread? </p>
  
  <p>Firstly I have no clue how to do this, and Google isn't much help. Secondly, I'm not sure if the fact I'm re-using cells when they go out of view (so I don't create 141 cells, one cell per image) makes a difference.</p>
  
  <p>Here's how I'm loading in the images:</p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
  
      if let cell = collectionView.dequeueReusableCellWithReuseIdentifier("TreeCell", forIndexPath: indexPath) as? TreeCell {
          cell.contentView.backgroundColor = UIColor.clearColor()
          let tree = Tree(treeNumber: (indexPath.row + 1))
          cell.configureCell(tree)
          return cell
      }
  
      else {
          return UICollectionViewCell()
      }
  } 
  </code></pre>
  
  <p>TreeCell for whoever asked:</p>
  
  <pre><code>var tree: Tree!
  
  required init?(coder aDecoder: NSCoder) {
      super.init(coder: aDecoder)
  
      layer.cornerRadius = 10.0
  }
  
  func configureCell(tree: Tree) {
      self.tree = tree
  
      treeCellImage.image = UIImage(named: "\(self.tree.treeNumber)")
  }
  </code></pre>
  
  <p>And the Tree class:</p>
  
  <pre><code>private var _treeNumber: Int!
  
  init(treeNumber: Int) {
      _treeNumber = treeNumber
  }
  
  var treeNumber: Int {
      return _treeNumber
  }
  </code></pre>