<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="">I was just discussing your first suggestion with a friend the other day. It’d be nice to see that happen so that more apis would be available to obj-c. I wonder how the following would be treated though?<div class=""><br class=""></div><div class="">swift:</div><div class=""><font face="Courier New" class="">class Foo: NSObject {</font></div><div class=""><font face="Courier New" class=""> class func printNumber(num: Int16?) {</font></div><div class=""><font face="Courier New" class=""> print(num)</font></div><div class=""><font face="Courier New" class=""> }</font></div><div class=""><font face="Courier New" class="">}</font></div><div class=""><br class=""></div><div class="">objc:</div><div class=""><font face="Courier New" class="">[Foo printNumber:[NSNumber numberWithInt:70000]];</font></div><div class=""><br class=""></div><div class="">Since NSNumber has no restrictions on what it can contain, it’s possible that one could pass a value that is outside the bounds of the type accepted by swift, which would likely crash your code.</div><div class=""><br class=""></div><div class="">If NSNumber were to bridge with optional scalars like this, the wrapped type for NSNumber would need to be present in the type signature of the obj-c code somehow so that the compiler could at the very least warn you. This could perhaps be done via obj-c lightweight generics (or per-scalar-type subclasses of NSNumber for each supported wrapped type, but that’s a bit odd).</div><div class=""><br class=""></div><div class="">You mention [Int] is bridged to NSArray<NSNumber *> * in objc, but [Int16] is not in my tests (probably for the reason I stated above). In my tests, [Bool], [Float], and [Double] also bridge today to that, so the same rules there could apply to optional versions.</div><div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">--</div><div class="">Kevin Lundberg</div></div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 27, 2016, at 5:48 PM, Mike Kasianowicz 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="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; line-height: normal; widows: 1;">Hello, I heard this is the place to talk about things we’d like to see in Swift.</div><div class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; line-height: normal; widows: 1;"><br class=""></div><div class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; line-height: normal; widows: 1;">There are a few improvements I’d like to see with Objective-C bridging. I find myself repeating the same three code patterns in order to have the best of both Objective-C and Swift worlds.</div><div class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; line-height: normal; widows: 1;"><br class=""></div><div class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; line-height: normal; widows: 1;">First, <b class="">optional primitive types should map to optional NSNumber</b>. Currently, they only map to NSNumber when used in an array or dictionary. The implicitly generated code would look like the following:</div><div class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; line-height: normal; widows: 1;"></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> optIntProperty: <span class="" style="color: rgb(112, 61, 170);">Int</span>?</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">@objc</span>(optIntProperty)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> objc_optIntProperty: <span class="" style="color: rgb(112, 61, 170);">NSNumber</span>? {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">get</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">guard</span> <span class="" style="color: rgb(187, 44, 162);">let</span> value = <span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">optIntProperty</span> <span class="" style="color: rgb(187, 44, 162);">else</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(112, 61, 170);">NSNumber</span>(integer: value)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">set</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">guard</span> <span class="" style="color: rgb(187, 44, 162);">let</span> value = newValue <span class="" style="color: rgb(187, 44, 162);">else</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">optIntProperty</span> = <span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">optIntProperty</span> = value.<span class="" style="color: rgb(112, 61, 170);">integerValue</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; widows: 1;">In the code above, you cannot mark the Int? property dynamic - it causes a compiler error - but it would be nice if you could. This feature would allow shared ObjC classes to be more Swifty, and enable existing runtime reflection/serialization code. I could also see utility of NSNull-nil bridging for values in collections, though this is a rarer case.</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; widows: 1;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; widows: 1;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small; widows: 1;"> </span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class="">Second, it would be nice for <b class="">C-style structs to bridge to NSValue by default.</b> Currently, every C struct has to implement NSValue bridging manually. I think it’s safe to say that if you mark a struct array property as @objc or dynamic that you typically want it to bridge to NSValue. Additionally, the same optional handling as noted above would be useful.</font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);">// pretend this struct were declared in C, or if we get struct exporting in the future (?)</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">struct</span> MyCStyleStruct {</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">var</span> intProp: <span class="" style="color: rgb(112, 61, 170);">Int</span></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">var</span> doubleProp: <span class="" style="color: rgb(112, 61, 170);">Float</span></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;">}</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><br class=""></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal; color: rgb(112, 61, 170);"><span class="" style="color: rgb(187, 44, 162);">extension</span><span class="" style=""> </span><span class="" style="color: rgb(79, 129, 135);">MyCStyleStruct</span><span class="" style=""> : </span>_ObjectiveCBridgeable<span class="" style=""> {</span></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">typealias</span> _ObjectiveCType = <span class="" style="color: rgb(112, 61, 170);">NSValue</span></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _isBridgedToObjectiveC() -> <span class="" style="color: rgb(112, 61, 170);">Bool</span> {</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);"><span class="" style=""> </span>return<span class="" style=""> </span>true</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> }</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _getObjectiveCType() -> <span class="" style="color: rgb(112, 61, 170);">Any</span>.Type {</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(112, 61, 170);">NSValue</span>.<span class="" style="color: rgb(187, 44, 162);">self</span></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> }</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _bridgeToObjectiveC() -> <span class="" style="color: rgb(79, 129, 135);">_ObjectiveCType</span> {</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">var</span> sself = <span class="" style="color: rgb(187, 44, 162);">self</span></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(0, 132, 0);">// would need compiler to create the @encode()</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(112, 61, 170);">NSValue</span>(&sself, withObjCType: <span class="" style="color: rgb(209, 47, 27);">"{MyCStyleStruct=if}"</span>)</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> }</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _forceBridgeFromObjectiveC(source: <span class="" style="color: rgb(79, 129, 135);">_ObjectiveCType</span>, <span class="" style="color: rgb(187, 44, 162);">inout</span> result: <span class="" style="color: rgb(79, 129, 135);">MyCStyleStruct</span>?) {</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> source.<span class="" style="color: rgb(61, 29, 129);">getValue</span>(&result)</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> }</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _conditionallyBridgeFromObjectiveC(source: <span class="" style="color: rgb(79, 129, 135);">_ObjectiveCType</span>, <span class="" style="color: rgb(187, 44, 162);">inout</span> result: <span class="" style="color: rgb(79, 129, 135);">MyCStyleStruct</span>?) -> <span class="" style="color: rgb(112, 61, 170);">Bool</span> {</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> <span class="" style="color: rgb(49, 89, 93);">_forceBridgeFromObjectiveC</span>(source, result: &result)</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal; color: rgb(187, 44, 162);"><span class="" style=""> </span>return<span class="" style=""> </span>true</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"> }</div></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;">}</div></div></div></blockquote><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class="">Finally, consider <b class="">automatic bridging of</b> <b class="">RawRepresentable</b> <b class="">types</b> (enums) as well, making the _ObjectiveCBridgeable code implicit in the following:</font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">enum</span> MyEnum: <span class="" style="color: rgb(112, 61, 170);">Int</span> {</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">case</span> Zero = <span class="" style="color: rgb(39, 42, 216);">0</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">case</span> One = <span class="" style="color: rgb(39, 42, 216);">1</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">case</span> Two = <span class="" style="color: rgb(39, 42, 216);">2</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">case</span> Three = <span class="" style="color: rgb(39, 42, 216);">3</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span class="" style="color: rgb(187, 44, 162);">extension</span><span class="" style=""> </span><span class="" style="color: rgb(79, 129, 135);">MyEnum</span><span class="" style=""> : </span>_ObjectiveCBridgeable<span class="" style=""> {</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">typealias</span> _ObjectiveCType = <span class="" style="color: rgb(112, 61, 170);">NSNumber</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _isBridgedToObjectiveC() -> <span class="" style="color: rgb(112, 61, 170);">Bool</span> {</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);"><span class="" style=""> </span>return<span class="" style=""> </span>true</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div></div><div class="" style="margin: 0px; line-height: normal;"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _getObjectiveCType() -> <span class="" style="color: rgb(112, 61, 170);">Any</span>.Type {</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(112, 61, 170);">NSNumber</span>.<span class="" style="color: rgb(187, 44, 162);">self</span></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div></div><div class="" style="margin: 0px; line-height: normal;"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _bridgeToObjectiveC() -> <span class="" style="color: rgb(79, 129, 135);">_ObjectiveCType</span> {</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(112, 61, 170);">NSNumber</span>(integer: <span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">rawValue</span>)</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div></div><div class="" style="margin: 0px; line-height: normal;"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _forceBridgeFromObjectiveC(source: <span class="" style="color: rgb(79, 129, 135);">_ObjectiveCType</span>, <span class="" style="color: rgb(187, 44, 162);">inout</span> result: <span class="" style="color: rgb(79, 129, 135);">MyEnum</span>?) {</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> result = <span class="" style="color: rgb(79, 129, 135);">MyEnum</span>(rawValue: source.<span class="" style="color: rgb(112, 61, 170);">integerValue</span>)</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div></div><div class="" style="margin: 0px; line-height: normal;"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">static</span> <span class="" style="color: rgb(187, 44, 162);">func</span> _conditionallyBridgeFromObjectiveC(source: <span class="" style="color: rgb(79, 129, 135);">_ObjectiveCType</span>, <span class="" style="color: rgb(187, 44, 162);">inout</span> result: <span class="" style="color: rgb(79, 129, 135);">MyEnum</span>?) -> <span class="" style="color: rgb(112, 61, 170);">Bool</span> {</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(49, 89, 93);">_forceBridgeFromObjectiveC</span>(source, result: &result)</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);"><span class="" style=""> </span>return<span class="" style=""> </span>true</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div></blockquote><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="widows: 1;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></span></div><div class="" style="widows: 1; margin: 0px; line-height: normal;"><font color="#222222" face="arial, sans-serif" size="2" class="">Opinions? Have any/all of these been discussed before?</font></div><div class="" style="widows: 1; margin: 0px; line-height: normal;"><font color="#222222" face="arial, sans-serif" size="2" class=""><br class=""></font></div><div class="" style="widows: 1; margin: 0px; line-height: normal;"><font color="#222222" face="arial, sans-serif" size="2" class="">Thanks!</font></div><div class="" style="widows: 1; margin: 0px; line-height: normal;"><font color="#222222" face="arial, sans-serif" size="2" class="">Mike</font></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>