<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">Swift 4 and the macOS 10.13 SDK added a new NSAttributedStringKey type for the keys that NSAttributedStrings use. The keys are then defined in an extension of NSAttributedStringKey, essentially like this in AppKit:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// AppKit/NSAttributedString.h (Objective-C)</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(186, 45, 162);" class="">extern</span> <span style="color: rgb(112, 61, 170);" class="">NSAttributedStringKey</span> NSFontAttributeName;</div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// Generated Swift Interface</div></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">extension</span><span style="color: #000000" class=""> </span>NSAttributedStringKey<span style="color: #000000" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">public</span><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">static</span><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">let</span><span style="color: #000000" class=""> font: </span>NSAttributedStringKey</div></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(0, 0, 0);" class="">}</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class="">How do I get my own custom NSAttributedStringKeys to be imported this way? When I do it like AppKit, it doesn’t seem to work:</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255);" class=""><div style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class="">// My Objective-C header</div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: rgb(186, 45, 162);" class="">extern</span> <span style="color: #703daa" class="">NSAttributedStringKey</span> ODRolloverTokenAttributeName;</div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: rgb(0, 132, 0);" class="">// Generated Swift Interface</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: #ba2da2" class="">static</span> <span style="color: #ba2da2" class="">let</span> ODRolloverTokenAttributeName: <span style="color: #703daa" class="">NSAttributedStringKey</span></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: #703daa" class=""><br class=""></span></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: #703daa" class=""><br class=""></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class="">That is obviously not the same. I tried using the NS_SWIFT_NAME macro, but that results in the symbol disappearing in Swift completely:</span></div><div style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="color: rgb(0, 132, 0);" class="">// My Objective-C header</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="color: #ba2da2" class="">extern</span> <span style="color: #703daa" class="">NSAttributedStringKey</span> ODRolloverTokenAttributeName <span style="color: #78492a" class="">NS_SWIFT_NAME</span>(NSAttributedStringKey.rolloverToken);</div></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div class="">I also tried to use the swift_name attribute that is used by the NS_SWIFT_NAME macro and that is even mentioned in SE-0044 for exactly this purpose, but the symbol still disappears:</div><div class=""><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0044-import-as-member.md#swift_name-attribute" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0044-import-as-member.md#swift_name-attribute</a></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: #ba2da2" class="">extern</span> <span style="color: #ba2da2" class="">const</span> <span style="color: #703daa" class="">NSAttributedStringKey</span> ODRolloverTokenAttributeName <span style="color: #ba2da2" class="">__attribute__</span>((swift_name(<span style="color: #d12f1b" class="">"NSAttributedStringKey.rolloverToken"</span>)));</div></div><div style="color: rgb(0, 0, 0); font-family: Menlo; font-size: 13px;" class=""><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">What works is to manually define it in an extension like this, but that’s no fun:</div></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(0, 132, 0);" class="">// My Objective-C header</span></div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo;" class=""><span style="color: #ba2da2" class="">extern</span> <span style="color: #703daa" class="">NSAttributedStringKey</span> ODRolloverTokenAttributeName <span style="color: #78492a" class="">NS_REFINED_FOR_SWIFT</span>;</div><div style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal; color: rgb(112, 61, 170);" class=""><span style="color: #ba2da2" class="">extension</span><span style="color: #000000" class=""> </span>NSAttributedStringKey<span style="color: #000000" class=""> {</span></div><div style="font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class=""> <span style="color: rgb(186, 45, 162);" class="">static</span> <span style="color: rgb(186, 45, 162);" class="">let</span> rolloverToken = <span style="color: rgb(112, 61, 170);" class="">NSAttributedStringKey</span>(<span style="color: rgb(79, 129, 135);" class="">__ODRolloverTokenAttributeName</span>.<span style="color: rgb(112, 61, 170);" class="">rawValue</span>)</div><div style="font-family: Menlo; font-size: 13px; margin: 0px; font-stretch: normal; line-height: normal;" class="">}</div><div style="font-family: Menlo; font-size: 13px;" class=""><br class=""></div><div style="font-family: Menlo; font-size: 13px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="font-family: Menlo; font-size: 13px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Is there no way to import this automatically? Was this functionality removed before release even though it was mentioned in SE-0044?</span></div><div style="font-family: Menlo; font-size: 13px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="font-family: Menlo; font-size: 13px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Cheers,</span></div><div style="font-family: Menlo; font-size: 13px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="font-family: Menlo; font-size: 13px;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Marco</span></div></div></div></div></div></div></body></html>