<div dir="ltr"><div>[TL;DR]</div><div>SE-0033 ports objective-c global strings to swift enums, but the reverse seems to be missing. There should be a swift construct that can be accessible by objective-c.</div><div><br></div><div>[Proposal]</div>In a previously implemented swift proposal, the concept of NS_STRING_ENUM and NS_EXTENSIBLE_STRING_ENUM was born.  (see: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md">https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md</a>  )<div><br></div><div>This would enable objective-c global strings to be ported over to swift as an enum and struct respectively.</div><div><br></div><div>I always found it odd that this interoperability only worked in one direction.  I think that enum strings should be accessible to Objective-c when it is marked with  the @objc attribute.  When an enum string has @objc it should be ported over to objective-c as global strings.</div><div><br></div><div>// Swift example</div><div>@objc</div><div>public enum Food: String {</div><div>   case Calamari </div><div>   case Fish</div><div>} </div><div><br></div><div>// Objective-c port</div><div>typedef NSString *_Nonnull Food;</div><div>static Food const Food_Calimari = @&quot;Calimari&quot;;</div><div>static Food const Food_Fish = @&quot;Fish&quot;;</div><div><br></div><div>The Objective-c port code could be added as part of the generated header file or a framework&#39;s umbrella header.</div><div><br></div><div>When a structs is given the attribute @objcextstring it should become available to objective-c as a class.  This attribute will put restrictions on the struct such that it only has static constants and a mandatory property called rawValue.  </div><div><br></div><div>// Swift example</div><div>@objcextstring</div><div>public struct Planets {</div><div>public let rawValue: String</div><div>public static let Earth = Planets(rawValue: &quot;Earth&quot;)<br></div><div>public static let Venus = Planets(rawValue: &quot;Venus&quot;)</div><div>}</div><div><br></div><div>// Objective-c port</div><div>@interface Planets: NSObject </div><div>+ (instanceType)Earth;<br></div><div>+ (instanceType)Venus;<br></div><div>@end</div><div><br></div><div>@implementation Planets</div><div><div>+ (instanceType)Earth { </div><div>return [[Planets alloc] initWithRawValue: @&quot;Earth&quot;]; </div><div>}<br></div><div>+ (instanceType)Venus { </div><div>return [[Planets alloc] initWithRawValue:@&quot;Venus&quot;]; </div><div>}</div></div><div>@end</div><div><br></div><div>What do you guys thinks of this proposal?  Do you think it will enhance the objective-c to swift interoperability?</div><div><br></div><div><br></div></div>