[TL;DR]
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.
[Proposal]
In a previously implemented swift proposal, the concept of NS_STRING_ENUM
and NS_EXTENSIBLE_STRING_ENUM was born. (see:
)
This would enable objective-c global strings to be ported over to swift as
an enum and struct respectively.
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.
// Swift example @objc
public enum Food: String {
case Calamari
case Fish
}
The Objective-c port code could be added as part of the generated header
file or a framework's umbrella header.
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.
// Swift example @objcextstring
public struct Planets {
public let rawValue: String
public static let Earth = Planets(rawValue: "Earth")
public static let Venus = Planets(rawValue: "Venus")
}
On Sat, Nov 19, 2016 at 2:44 PM Derrick Ho <wh1pch81n@gmail.com> wrote:
[TL;DR]
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.
This would enable objective-c global strings to be ported over to swift as
an enum and struct respectively.
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.
// Swift example @objc
public enum Food: String {
case Calamari
case Fish
}
The Objective-c port code could be added as part of the generated header
file or a framework's umbrella header.
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.
// Swift example @objcextstring
public struct Planets {
public let rawValue: String
public static let Earth = Planets(rawValue: "Earth")
public static let Venus = Planets(rawValue: "Venus")
}
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.
···
On Sun, 20 Nov 2016 at 18:15 Derrick Ho via swift-evolution < swift-evolution@swift.org> wrote:
On Sat, Nov 19, 2016 at 2:44 PM Derrick Ho <wh1pch81n@gmail.com> wrote:
[TL;DR]
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.
This would enable objective-c global strings to be ported over to swift as
an enum and struct respectively.
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.
// Swift example @objc
public enum Food: String {
case Calamari
case Fish
}
The Objective-c port code could be added as part of the generated header
file or a framework's umbrella header.
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.
// Swift example @objcextstring
public struct Planets {
public let rawValue: String
public static let Earth = Planets(rawValue: "Earth")
public static let Venus = Planets(rawValue: "Venus")
}