<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>&nbsp;*strings =&nbsp;<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>&nbsp;(<span class="" style="color: rgb(112, 61, 170);">NSString</span>&nbsp;*string&nbsp;<span class="" style="color: rgb(187, 44, 162);">in</span>&nbsp;strings) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; …</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&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">Optional</span>&nbsp;type conform to&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span>&nbsp;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&nbsp;<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;">&lt;</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;">&gt;</span>&nbsp;and a&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span>.&nbsp;Therefore, I’d prefer a specialized syntax to make a clear distinction between iterating over a&nbsp;<span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">SequenceType</span>&nbsp;and an&nbsp;<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;">&lt;</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;">&gt;</span>.</div></div></div></blockquote><div class=""><br class=""></div>Actually it depends on how the conformance was defined. If Optional&lt;T&gt; was a sequence iff T is a sequence, then yes it supersedes your proposal. Another way to imagine Optional&lt;T&gt; 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>