Arrays and Optionals


(Sean Kosanovich) #1

Hello all!

I have been using Swift nearly exclusively for iOS projects since its release (for better or worse). I love the fact that a compiling application gives me some sort of guarantee that I won’t encounter a nil reference (unless of course I ignore optionals and force unwrap them…not a great idea).

When pulling values out of a Dictionary, we get an Optional value which makes perfect sense. Why does this not extend out to Arrays? There is no guarantee that when I am pulling the 8th element out, that it will have a valid value.

It seems odd to me that Optionals are a fundamental part of the language but they don’t extend to Arrays.

Thanks,
Sean


(Marc Knaup) #2

Hey Sean,

Jordan Rose answered this question yesterday in a different discussion:
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/002425.html

···

On Tue, Dec 15, 2015 at 1:08 PM, Sean Kosanovich via swift-evolution < swift-evolution@swift.org> wrote:

Hello all!

I have been using Swift nearly exclusively for iOS projects since its
release (for better or worse). I love the fact that a compiling
application gives me some sort of guarantee that I won’t encounter a nil
reference (unless of course I ignore optionals and force unwrap them…not a
great idea).

When pulling values out of a Dictionary, we get an Optional value which
makes perfect sense. Why does this not extend out to Arrays? There is no
guarantee that when I am pulling the 8th element out, that it will have a
valid value.

It seems odd to me that Optionals are a fundamental part of the language
but they don’t extend to Arrays.

Thanks,
Sean
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution