<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 Dec 4, 2015, at 2:06 PM, Dan Stenmark <<a href="mailto:daniel.j.stenmark@gmail.com" class="">daniel.j.stenmark@gmail.com</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 style="margin: 0px; line-height: normal;" class="">Swift’s Struct type is one of the most praised features of the language, but is currently unavailable in Objective-C. This poses problems for large legacy codebases that can’t be ported to Swift as quickly but still want to begin using some of the mutability semantics it introduces. As such, I’d like to propose syntax for creating bridged classes that can utilized in Objective-C.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">@objc struct Letter {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var address : String?</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init(withAddress address : String? ) {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>self.address = address</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div></div></div></blockquote><div><br class=""></div><div>I’m generally a fan of anything that can make Swift get exposed back to Objective-C better, but such things generally need implementation work on Clang as well as on Swift (and thus, need Clang community buy-in as well). Further, as other folks have pointed out, as proposed, this has some challenges in terms of design and implementation. Are you planning to lead the implementation effort?</div><div><br class=""></div><div>-Chris</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">At compile-time, this would create two bridge classes: <b class="">Letter</b> and <b class="">MutableLetter</b>, both conforming to the NSMutableCopying protocol.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">Letter *letter = [[Letter alloc] initWithAddress:address]; // equivalent to ‘let letter = Letter(address: address)’</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">MutableLetter *mutableLetter = letter.mutableCopy; // equivalent to ‘var mutableLetter = letter’</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">With Objective-C’s lack of namespacing, the @objc decorator would likely need to accept an optional class prefix parameter to help guard against class name collisions.</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">@objc(US) struct Letter {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var address : String?</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>init(withAddress address : String? ) {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>self.address = address</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">-------</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">USLetter *letter = [[USLetter alloc] initWithAddress:address]; // equivalent to ‘let letter = Letter(address: address)’</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">USMutableLetter *mutableLetter = letter.mutableCopy; // equivalent to ‘var mutableLetter = letter’</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Nested types would also be represented via this proposal:</div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">@objc(US) class PostalService {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>struct Letter {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>var address : String?</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font face="Courier New" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>init(withAddress address : String? ) {</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                        </span>self.address = address</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class="">-------</div><div class=""><br class=""></div></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">USPostalServiceLetter *letter = [[USPostalServiceLetter alloc] initWithAddress:address]; // equivalent to ‘let letter = PostalService.Letter(address: address)’</font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Courier New" class="">USMutablePostalServiceLetter *mutableLetter = letter.mutableCopy; // equivalent to ‘var mutableLetter = letter’</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Dan</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RC5Cq0zAxCHc1sM9Uy3-2BojrrUAw-2F96zH69NULNHPvCuk9zyAxOJbCcmuNq4R8iksFU0jtWMkYk36TujDuNkmhqo9N1bMkpbsu356U-2B4svFKY-2BAzr349Q7XENlU28p-2BOK69AMDc2etZEVMZZdt9Ip2k9RFc3Ws9PkR9ZKR9zGZiAEyyzKffCQUAR5w8mFShNxORzEplfh-2BuMw1wfX3Fo7MGtNc748KLKVQ0Vcl8UPAVA-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</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=""></body></html>