¿Búsqueda segura de matrices (verificación de límites) en Swift, a través de enlaces opcionales?

Si tengo una matriz en Swift e intento acceder a un índice que está fuera de los límites, hay un error de tiempo de ejecución poco sorprendente:

var str = ["Apple", "Banana", "Coconut"]

str[0] // "Apple"
str[3] // EXC_BAD_INSTRUCTION

Sin embargo, habría pensado con todo el encadenamiento opcional yla seguridad que Swift trae, sería trivial hacer algo como:

let theIndex = 3
if let nonexistent = str[theIndex] { // Bounds check + Lookup
    print(nonexistent)
    ...do other things with nonexistent...
}

En lugar de:

let theIndex = 3
if (theIndex < str.count) {         // Bounds check
    let nonexistent = str[theIndex] // Lookup
    print(nonexistent)   
    ...do other things with nonexistent... 
}

Pero este no es el caso, tengo que usar el viejoif declaración para verificar y garantizar que el índice sea inferior astr.count.

Traté de agregar el míosubscript() implementación, pero no estoy seguro de cómo pasar la llamada a la implementación original o acceder a los elementos (basados en índices) sin usar la notación de subíndice:

extension Array {
    subscript(var index: Int) -> AnyObject? {
        if index >= self.count {
            NSLog("Womp!")
            return nil
        }
        return ... // What?
    }
}

Respuestas a la pregunta(11)

Su respuesta a la pregunta