In this article we try to know why not everything in swift is optional even swift is safe language.
let a = [10]
print(a[1]) // fatal Error: Array out on index
Under the beneath
Protocol Collection {
subscript(position: Index) -> Element { get }
}
Swift is safer language but why it is not returning some nil value or give some catch with error handling ??
Let take the case when swift give option value from collection iteration code looks like this
for i in data.indices {
data[i]! = data[i]! * 2 // assume that 'data[i]!' can be made settable.
}
If every API can fail, then you can't write useful code. You need to have some fundamental basis that you can rely on, and trust to operate correctly. Otherwise your code gets bogged down in safety checks.
Source: Swift Evolution Mailing List