0

For Dictionaries the subscript is declared like this:

subscript (key: Key) -> Value?

And for Array:

subscript (index: Int) -> T

I want to do like this with an array:

let something = arr[index] ?? somethingElse

Is there any existing method to return nil if out of bounds instead of crashing and without having to check for Array count?

Arbitur
  • 37,971
  • 22
  • 89
  • 126

0 Answers0