<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 16, 2016, at 15:07, David Turnbull via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Sat, Jan 16, 2016 at 2:46 PM, Adriano Ferreira via swift-users <span dir="ltr" class="">&lt;<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Isn’t the subscript supposed to return an optional as well?</div></div></blockquote><div class=""><br class=""></div><div class="">Not arrays. They stop your program when out of bounds.</div><div class="">&nbsp;</div></div></div></div></div></blockquote><br class=""></div><div>For the record, this isn't a difference between arrays and other collections. <i class="">All</i>&nbsp;Collections return a non-optional value when subscripted by an Index, with the assumption that you shouldn't be putting random indexes into a collection unless they came from that collection in the first place, or have been already validated in some way. With 'first', on the other hand, it's very convenient to be able to say "collection.first ?? defaultValue".</div><div><br class=""></div><div>"But what about dictionaries?" Ah, but a dictionary key is not an Index (note the capital). The relation between a Collection and an Index is that there must be a constant-time operation to get to a value from an Index. There's a separate DictionaryIndex that represents a position in a dictionary for that purpose.</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>