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
  • 38,684
  • 22
  • 91
  • 128

0 Answers0