<div dir="ltr">&gt; <span style="font-size:12.8px">The problem is that NSNull is in fact rare in Cocoa.</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I couldn&#39;t agree more. I think this proposal is quite dangerous for (often legacy) Objective C codebases where checking for NSNull is not common practice. Since Optionals are not a construct in Objective C, I don&#39;t see any reason for why Objective C Collection types would be populated with Optionals unless it&#39;s unintentional. </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I&#39;m not sure whether it&#39;s possible, but an ideal solution would be if the Swift Compiler can give a type error when passing an Optional to an Objective C Collection type.</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 25, 2016 at 9:27 AM, Greg Parker via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</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"><br><div><span class=""><blockquote type="cite"><div>On Aug 23, 2016, at 3:36 PM, Douglas Gregor via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><h2 style="margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;background-color:rgb(255,255,255)">Proposed solution</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,&#39;Segoe UI&#39;,Roboto,Helvetica,Arial,sans-serif,&#39;Apple Color Emoji&#39;,&#39;Segoe UI Emoji&#39;,&#39;Segoe UI Symbol&#39;;font-size:16px;background-color:rgb(255,255,255)">When an <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Optional&lt;T&gt;</code> value is bridged to an Objective-C object, if it contains <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">some</code> value, that value should be bridged; otherwise, <code style="font-family:Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">NSNull</code> or another sentinel object should be used.</p></div></div></blockquote></span>I don&#39;t think I like this.</div><div><br></div><div>Let me verify my understanding. If I have this:</div><div><br></div><div><font face="Menlo">    // imported from ObjC</font></div><div><font face="Menlo">    func f(with object: Any)</font></div><div><font face="Menlo">    </font></div><div><font face="Menlo">    let s: String? = nil</font></div><div><font face="Menlo">    f(s)</font></div><div><br></div><div>then at runtime it will call </div><div><font face="Menlo">    f([NSNull null])</font></div><div>?</div><div><br></div><div>The problem is that NSNull is in fact rare in Cocoa. They are used in the Foundation containers and almost nowhere else. Passing NSNull into almost any API is going to do something confusing at runtime. If you&#39;re lucky you get a prompt error &quot;-[NSNull something]: unrecognized selector&quot;. If you&#39;re not lucky you&#39;ll get that error somewhere much later, or something even less obviously related to NSNull and your call site. That sounds like the wrong outcome for developers who are confused or careless or unaware of an optional.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div>-- </div><div>Greg Parker     <a href="mailto:gparker@apple.com" target="_blank">gparker@apple.com</a>     Runtime Wrangler</div><div><br></div><div><br></div></font></span></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>