title: swift conditional function return
body: <p>I would like to know how to manage conditional returns in swift. For instance, I'm returning a custom UICollectionViewCell depending on which collectionview delegate is called:</p>
  
  <pre><code>    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
        if (collectionView.isEqual(collectionView1)) {
           var cell = self.epgCollectionView.dequeueReusableCellWithReuseIdentifier("Cell1", forIndexPath: indexPath) as Cell1
           return cell
        }
        else if (collectionView.isEqual(collectionView2)) {
          var cell = self.epgCollectionView.dequeueReusableCellWithReuseIdentifier("Cell2", forIndexPath: indexPath) as Cell2
          return cell
        }
  }
  </code></pre>
  
  <p>The compiler says "Missing return statement in a function expeted to return UICollectionViewCell", even in both cases I'm returning a cell. </p>
  
  <p>I solved it adding</p>
  
  <pre><code>return UICollectionViewCell()
  </code></pre>
  
  <p>at the bottom of the function, but I don't think it's the correct way.</p>
  
  <p>I know I can declare the cell above the first 'if', modify it and return it at the end of the function outside the 'if', but then the 'dequeueReusableCellWithIdentifier' call hangs.</p>
  
  <p>Thank you all.</p>