<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 20, 2017, at 12:47 PM, Philippe Hausler &lt;<a href="mailto:phausler@apple.com" class="">phausler@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><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; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">With the introduction of SE-0170 the behavior is a bit more predicable: The rule is that if the value would not loose mantissa representation or significant bits of the representation it will bridge to the target type in all scenarios, no matter if it is created in objc or in swift.</span><div class="" 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; -webkit-text-stroke-width: 0px;"><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On May 19, 2017, at 9:00 PM, David Waite via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">When I call such a mapped Swift API that expects an Int? parameter from Objc with a NSNumber initialized with 3.5, what should happen?&nbsp;</div></div></blockquote><div class=""><br class=""></div><div class="">NSNumber(value: 3.5) as? Int == nil</div><div class=""><br class=""></div><div class="">But</div><div class=""><br class=""></div><div class="">NSNumber(value: 3.5).intValue == 3</div></div></div></div></div></blockquote><div><br class=""></div>as? now has the closest to predictable behavior, but I would argue that in terms of generalizing a transform, the meaning of ‘nil’ for an Int? parameter may not match the behavior one would expect passing in a value which was not an integer value - say using 3.00000000004 as the argument (due to rounding errors) rather than the integer 3.</div><div><br class=""></div><div>The safest default behavior (should a nullable NSNumber be used to represent an Int? parameter) would probably be to fatalError out if the user passed a NSNumber with a value which was not exactly an Int. No NSNumber instance would be interpreted as ‘nil’ once bridged into Swift.</div><div><br class=""></div><div>This still allows the odd edge case of a boolean value being interpreted as 1, which could cause interface comprehension issues if Bool? was also mapped to NSNumber in Objc interfaces.</div><div><br class=""></div><div>-DW</div></body></html>