<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><div><span></span></div><div><div></div><div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">Ah ok, I was using the other version which distinguishes between nil and Optional(nil):</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div class="" style="margin: 0px; line-height: normal;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">extension<span class="">&nbsp;</span><span class="">Array</span><span class="">&nbsp;{</span></span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp;&nbsp;<span class="">subscript</span>(ifExists idx:&nbsp;<span class="">Index</span>) -&gt;&nbsp;<span class="">Element</span>? {</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">get</span>&nbsp;{&nbsp;<span class="">return</span>&nbsp;(<span class="">startIndex</span>&nbsp;..&lt;&nbsp;<span class="">endIndex</span>) ~= idx ?&nbsp;<span class="">self</span>[idx] :&nbsp;<span class="">nil</span>&nbsp;}</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="">set</span>&nbsp;{&nbsp;<span class="">if</span>&nbsp;(<span class="">startIndex</span>&nbsp;..&lt;&nbsp;<span class="">endIndex</span>) ~= idx &amp;&amp; newValue !=&nbsp;<span class="">nil</span>&nbsp;{&nbsp;<span class="">self</span>[idx] = newValue! } }</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; }</span></font></div><div class="" style="margin: 0px; line-height: normal;"><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">}</span></font></div></div></div></div></div></div></div></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">Where you can assign Optional(nil) to set a value to nil which is admittedly not very intuitive...</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">var array: [Int?] = [1]</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">array[ifExists: 0] = Optional(nil)</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">print(array) // "[nil]"</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">array = [1]</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">array[ifExists: 0] =&nbsp;array[ifExists: 1]</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">print(array) // "[Optional(1)]"</span></div></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">A solution would probably be to introduce another enum mimicking Optional but built for the array subscript which allows to distinguish both cases.</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">-Thorsten&nbsp;</span></div><div><br>Am 06.02.2016 um 21:52 schrieb Maximilian Hünenberger &lt;<a href="mailto:m.huenenberger@me.com">m.huenenberger@me.com</a>&gt;:<br><br></div><blockquote type="cite"><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">var array: [Int?] = [1]</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">array[ifExists: 0] = nil // sets array[0] to nil if index is valid</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">print(array) // "[nil]"</span></div><div class="" style="margin: 0px; line-height: normal;">array = [1]</div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">array[ifExists: 0] =&nbsp;array[ifExists: 1]</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);">print(array) // "[nil]"</span></div></blockquote></div></div></body></html>