<div dir="ltr">Hi Charles,<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>If Swift code were to send NSNotFound to a method that took a nullable NSArrayIndex, under this example, one of two things could happen:</div><div><br></div><div>1.) The Swift compiler fails with a fix-it to use nil instead.</div><div>2.) The value is passed as-is and Objective-C handles it as usual.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>My preference would be for 1, as then the fix-its can help update code to use the new syntax, but my opinion can definitely be swayed.</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="font-family:Helvetica"><br></div><div style="font-family:Helvetica">Jeff Kelley</div><div style="font-family:Helvetica"><br></div><div style="font-family:Helvetica"><a href="mailto:SlaunchaMan@gmail.com" style="color:rgb(17,85,204)" target="_blank">SlaunchaMan@gmail.com</a> | <a href="https://twitter.com/SlaunchaMan" style="color:rgb(17,85,204)" target="_blank">@SlaunchaMan</a> | <a href="http://jeffkelley.org/" style="color:rgb(17,85,204)" target="_blank">jeffkelley.org</a></div></div></div></div>
<br><div class="gmail_quote">On Fri, Feb 17, 2017 at 3:24 PM, Charles Srstka <span dir="ltr">&lt;<a href="mailto:cocoadev@charlessoft.com" target="_blank">cocoadev@charlessoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><blockquote type="cite">On Feb 13, 2017, at 9:33 PM, Jeff Kelley via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></blockquote><div><blockquote type="cite"><br class="m_781033541834196190Apple-interchange-newline"><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Hi all,</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_781033541834196190gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>I don’t have a formal proposal written up yet, but in my continued quest to make better-annotated Objective-C code, I had an idea for bridging<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">nil</font><span class="m_781033541834196190Apple-converted-space"> </span>with primitives. Since in Objective-C we often use constant values to represent invalid values or <font face="monospace, monospace">nil</font>, the most obvious being<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">NSNotFound</font>, could we use that as a shorthand for<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">nil</font>? Something like this for<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">NSArray</font>:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="monospace, monospace">- (NSUInteger NS_SWIFT_NIL(NSNotFound))<wbr>indexOfObject:(ObjectType)<wbr>anObject;</font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_781033541834196190gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>This is a little verbose, so it could also work with a<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">typedef</font>:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="monospace, monospace">typedef NSUInteger NS_SWIFT_NIL(NSNotFound) NSArrayIndex;</font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font face="monospace, monospace">- (NSArrayIndex)indexOfObject:(<wbr>ObjectType)anObject;</font><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_781033541834196190Apple-tab-span" style="white-space:pre-wrap">        </span>This would change the existing Swift interface to return an<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">Int?</font><span class="m_781033541834196190Apple-converted-space"> </span>instead of an<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">Int</font>. I see this as working both ways—converting these values to<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">nil</font><span class="m_781033541834196190Apple-converted-space"> </span>when returning from Objective-C to Swift, and sending these values instead of<span class="m_781033541834196190Apple-converted-space"> </span><font face="monospace, monospace">nil</font><span class="m_781033541834196190Apple-converted-space"> </span>when Swift calls into Objective-C code.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span class="m_781033541834196190Apple-tab-span" style="white-space:pre-wrap">        </span>Is this worth writing up a proposal for? Is another, better method already in someone’s mind?</div></div></blockquote></div><br></span><div>What happens if code on the Swift side sets the property’s value to the sentinel?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Charles</div><div><br></div></font></span></div></blockquote></div><br></div>