<div dir="ltr">It seems like a sensible/reasonable approach, but personally I don't care about accessing Swift from Obj-C, or writing Swift that can be called from Obj-C.<br></div><br><div class="gmail_quote"><div dir="ltr">On Sun, 20 Nov 2016 at 18:15 Derrick Ho via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">Does anyone have any thoughts on this idea?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I Made a draft proposal of this very idea</div><a href="https://github.com/wh1pch81n/swift-evolution/blob/master/proposals/NNNN-Swift-enum-strings-ported-to-Objective-c" class="gmail_msg" target="_blank">https://github.com/wh1pch81n/swift-evolution/blob/master/proposals/NNNN-Swift-enum-strings-ported-to-Objective-c</a><br class="gmail_msg"></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Sat, Nov 19, 2016 at 2:44 PM Derrick Ho <<a href="mailto:wh1pch81n@gmail.com" class="gmail_msg" target="_blank">wh1pch81n@gmail.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">[TL;DR]</div><div class="gmail_msg">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 class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">[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" class="gmail_msg" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md</a> )<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">This would enable objective-c global strings to be ported over to swift as an enum and struct respectively.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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 class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">// Swift example</div><div class="gmail_msg">@objc</div><div class="gmail_msg">public enum Food: String {</div><div class="gmail_msg"> case Calamari </div><div class="gmail_msg"> case Fish</div><div class="gmail_msg">} </div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">// Objective-c port</div><div class="gmail_msg">typedef NSString *_Nonnull Food;</div><div class="gmail_msg">static Food const Food_Calimari = @"Calimari";</div><div class="gmail_msg">static Food const Food_Fish = @"Fish";</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The Objective-c port code could be added as part of the generated header file or a framework's umbrella header.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">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 class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">// Swift example</div><div class="gmail_msg">@objcextstring</div><div class="gmail_msg">public struct Planets {</div><div class="gmail_msg">public let rawValue: String</div><div class="gmail_msg">public static let Earth = Planets(rawValue: "Earth")<br class="gmail_msg"></div><div class="gmail_msg">public static let Venus = Planets(rawValue: "Venus")</div><div class="gmail_msg">}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">// Objective-c port</div><div class="gmail_msg">@interface Planets: NSObject </div><div class="gmail_msg">+ (instanceType)Earth;<br class="gmail_msg"></div><div class="gmail_msg">+ (instanceType)Venus;<br class="gmail_msg"></div><div class="gmail_msg">@end</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">@implementation Planets</div><div class="gmail_msg"><div class="gmail_msg">+ (instanceType)Earth { </div><div class="gmail_msg">return [[Planets alloc] initWithRawValue: @"Earth"]; </div><div class="gmail_msg">}<br class="gmail_msg"></div><div class="gmail_msg">+ (instanceType)Venus { </div><div class="gmail_msg">return [[Planets alloc] initWithRawValue:@"Venus"]; </div><div class="gmail_msg">}</div></div><div class="gmail_msg">@end</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">What do you guys thinks of this proposal? Do you think it will enhance the objective-c to swift interoperability?</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div></div></blockquote></div>
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>