title: How can I use a 3d array as a datasource for a UICollectionView in Swift?
body: <p>I have a datasource that is a three dimensional array.</p>
  
  <p>I am using the first dimension count as the number of sections.</p>
  
  <p>I am using the third dimension as the items in each section.</p>
  
  <p>Here is some sample data:</p>
  
  <pre><code>let sentence1 = [word1, word2, word1] // These are Word objects
  let sentence2 = [word1, word2, word3] // in my model.
  let sentence3 = [word4, word5, word3]
  
  let paragraph1 = [sentence1, sentence2] // These are Sentence objects.
  let paragraph2 = [sentence1, sentence3]
  
  let article = [paragraph1, paragraph2]
  </code></pre>
  
  <p>Currently I have just made a copy of 3dArray and flattened the second and third dimension into one dimension thus making the three dimensional array into a two dimensional array. I am then returning new2dArray.count as the numberOfSectionsInCollectionView and making cells, in cellForItemAtIndexPath, with something like this:</p>
  
  <pre><code>let cell: UICollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as UICollectionViewCell
  
  let cellLabel = new2dArray[indexPath.section][indexPath.row]
  </code></pre>
  
  <p>However, in my didSelectItemAtIndexPath I need access to the 2nd dimension of 3dArray. I am looking for something like this:</p>
  
  <pre><code>func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
      println("did select cell \(indexPath.row) inside of \(secondDimension) inside of \(indexPath.section)")
  </code></pre>
  
  <p>What do I need to do?</p>