<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>You are totally right. The return type is "Int??".</div><div><br></div><div>My point was that if we allowed something like this (as suggested by Dave Sweeris I think):</div><div><br></div><div> var array: [Int?] = [1]</div><div> array[ifExists: 0] = nil</div><div><br></div><div>To set the element at index 0 to nil instead of doing nothing.</div><div>The next example would also set index 0 to nil even though the getter failed:</div><div><br></div><div> <span style="background-color: rgba(255, 255, 255, 0);">array[ifExists: 0] = array[ifExists: 1]</span></div><div><br></div><div><br></div><div>- Maximilian</div><div><br>Am 05.02.2016 um 10:20 schrieb Haravikk <<a href="mailto:swift-evolution@haravikk.me">swift-evolution@haravikk.me</a>>:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On 4 Feb 2016, at 20:24, Maximilian Hünenberger via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I just realized that the normal setter for failable lookups is very nice in case of assigning/swapping:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" 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; font-family: 'Fira Mono'; color: rgb(147, 161, 161);"><div class="" style="margin: 0px; line-height: normal; color: rgb(211, 54, 130);">extension<span class="" style="color: rgb(147, 161, 161);"> </span><span class="" style="color: rgb(39, 139, 210);">Array</span><span class="" style="color: rgb(147, 161, 161);"> {</span></div><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(211, 54, 130);">subscript</span>(ifExists idx: <span class="" style="color: rgb(39, 139, 210);">Index</span>) -> <span class="" style="color: rgb(39, 139, 210);">Element</span>? {</div><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(211, 54, 130);">get</span> { <span class="" style="color: rgb(211, 54, 130);">return</span> (<span class="" style="color: rgb(39, 139, 210);">startIndex</span> ..< <span class="" style="color: rgb(39, 139, 210);">endIndex</span>) ~= idx ? <span class="" style="color: rgb(211, 54, 130);">self</span>[idx] : <span class="" style="color: rgb(211, 54, 130);">nil</span> }</div><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(211, 54, 130);">set</span> { <span class="" style="color: rgb(211, 54, 130);">if</span> (<span class="" style="color: rgb(39, 139, 210);">startIndex</span> ..< <span class="" style="color: rgb(39, 139, 210);">endIndex</span>) ~= idx && newValue != <span class="" style="color: rgb(211, 54, 130);">nil</span> { <span class="" style="color: rgb(211, 54, 130);">self</span>[idx] = newValue! } }</div><div class="" style="margin: 0px; line-height: normal;"> }</div><div class="" style="margin: 0px; line-height: normal;">}</div></div></div></div></blockquote></div><div class=""><br class=""></div><div class=""> // array[index1] is only set if both indexes are valid</div><div class=""> array[ifExists: index1] = array[ifExists: index2] </div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">if array is of type [Int?] and the special setter for optional Elements would have been added:</div><div class=""><br class=""></div><div class="">array[index1] would be set to "nil" if array[index2] is nil <b style="text-decoration: underline;" class="">or</b> index2 is not valid which is unfortunate.</div></div></div></blockquote></div><br class=""><div class="">Wouldn’t the return type be Int?? in this case? It’s not as pretty to test for as a plain Int? but iirc you can still distinguish a return type of nil from an optional that happens to contain nil, which should allow you to tell the difference between a nil value and an invalid index, I just can’t recall how at the moment (as I design around cases like these like my life depends on it ;)</div></div></blockquote></body></html>