title: Swift Array - Check if an index exists
body: <p>In Swift, is there any way to check if an index exists in an array without a fatal error being thrown?</p>
  
  <p>I was hoping I could do something like this:</p>
  
  <pre><code>let arr: [String] = ["foo", "bar"]
  let str: String? = arr[1]
  if let str2 = arr[2] as String? {
      // this wouldn't run
      println(str2)
  } else {
      // this would be run
  }
  </code></pre>
  
  <p>But I get</p>
  
  <blockquote>
    <p>fatal error: Array index out of range</p>
  </blockquote>