<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=""><div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class="">In Objective-C, I liked that fast enumeration over an NSArray that was nil and one that was empty could be handled with the exact same code:<br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(112, 61, 170);">NSArray</span> *strings = <span class="" style="color: rgb(187, 44, 162);">nil</span>;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">for</span> (<span class="" style="color: rgb(112, 61, 170);">NSString</span> *string <span class="" style="color: rgb(187, 44, 162);">in</span> strings) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> …</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></div></div></blockquote><div class=""><br class=""></div>One thing we've discussed is adding attributes to import nil values of NSArray and such as empty arrays in Swift, rather than optionals of arrays. Would this solve your problem? Where are these optional arrays coming from in the first place, is it imported Cocoa APIs?</div></div></blockquote><div><br class=""></div><div>Yes, mostly. But I still can imagine cases where it makes sense to have an API that returns an Optional Array but the caller doesn’t care about it being nil vs. it being empty – not that I have a practical example.</div><div><br class=""></div><div>Importing an Objective-C API’s NSArray nil value as an empty array in Swift sounds nice!</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">Also, this is not a proposal to make the <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Optional</span> type conform to <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span> as was also discussed previously. If that were to be implemented, my proposal would be pointless, but you’d lose the distinction between iterating over an <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Optional</span><span class="" style="font-family: Menlo; font-size: 11px;"><</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">></span> and a <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span>. Therefore, I’d prefer a specialized syntax to make a clear distinction between iterating over a <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span> and an <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Optional</span><span class="" style="font-family: Menlo; font-size: 11px;"><</span><span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span><span class="" style="font-family: Menlo; font-size: 11px;">></span>.</div></div></div></blockquote><div class=""><br class=""></div>Actually it depends on how the conformance was defined. If Optional<T> was a sequence iff T is a sequence, then yes it supersedes your proposal. Another way to imagine Optional<T> as a sequence is to make it a zero- or one-element sequence, depending on if it is None or Some, respectively. I'm not sure which, if either, is more useful.</div></div></div></blockquote><br class=""></div>I have to admit that I didn’t closely follow the discussion about Optionals being sequences of zero or one element and therefore don’t know all of the arguments for and against that – just enough that it would supersede my proposal.</body></html>