title: Non empty array, accessing first element: index out of range (Swift 2.0)
body: <p>I have an array of 4 <code>UIImageVIew</code> and array of images of variable size: <code>[UIImage]</code>.</p>
  
  <p>I would like to iterate through the array of views and assign 4 last images to each view.</p>
  
  <pre><code>let photos = images.suffix(4)
  for (index, view) in views.enumerate() {
    if index &lt;= photos.count - 1 {
      view.image = photos[index]
    } else {
      view.image = nil
    }
  }
  </code></pre>
  
  <p>Code works perfectly if there are no more than 4 elements in <code>images</code>. Then I got a crash: <code>fatal error: ArraySlice index out of range</code>.</p>
  
  <p>I printed out <code>index</code> in for-loop and it seems that crash happens when index is <code>0</code>. <code>views.count</code> and <code>photos.count</code> return <code>4</code> in the same loop.</p>
  
  <p>So, I get an error when accessing the first - <code>0</code> element of an non-empty array.</p>
  
  <p>In Swift 1.2 this code worked flawlessly:</p>
  
  <pre><code>let photos = suffix(images, 4)
  for (index, view) in enumerate(views) {
    if index &lt;= photos.count - 1 {
      view.image = photos[index]
    } else {
      view.image = nil
    }
  }
  </code></pre>
  
  <p>The only change after switching to 2.0 is in <code>suffix</code> and <code>enumerate</code> methods.</p>
  
  <p>Does it look like a Swift 2.0 bug or am I doing something wrong?
  <a href="https://github.com/hyperoslo/ImagePicker/blob/swift-2.0/Source/BottomView/StackView.swift" rel="nofollow">Link to source file</a></p>
  
  <p><strong>Solution I've finished with:</strong></p>
  
  <pre><code>let photos = Array(images.suffix(4))
  </code></pre>
  
  <p>Should work exactly as <code>suffix()</code>  function in <code>Swift 1.2</code></p>