Array.subscript should return Optional

Originator:robnapier
Number:rdar://17937594 Date Originated:06-Aug-2014 06:17 PM
Status:Behaves Correctly Resolved:
Product:Swift Product Version:6.0beta5
Classification: Reproducible:
 
Array.subscript currently returns an element or crashes. This is highly unsafe, especially compared to Dictionaries which do not have this problem. Rather then crashing, Array.subscript should return an Optional<T>.

In general, callers should not be accessing Array subscripts directly; they should iterate with for...in. The very small overhead of using an Optional will encourage that. For users who wish a dangerous behavior, they can unwrap with !.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!