Swift poza związanym elelemnt

extension Collection {
    subscript(safe index: Index) -> Element? {
        return indices.contains(index) ? self[index] : nil
    }
}
Healthy Hippopotamus