You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe this is a Huge bug. In Xcode 8 we were given NS_STRING_ENUM and NS_EXTENSIBLE_STRING_ENUM. The former is suppose to turn objective-c Global strings into swift enum strings while the latter turns objective-c Global strings into swift structs with constant variable strings.
Steps to Reproduce:
Suppose we have the following objective-c header file
// traffic.h
typedef NSString * TrafficLightColor NS_STRING_ENUM;
When we try to access TrafficLightColor in swift, it is treated as a struct. below is the Generated interface produced by Xcode:
struct TrafficLightColor : RawRepresentable, _SwiftNewtypeWrapper, Equatable, Hashable, Comparable, _ObjectiveCBridgeable {
static let red: TrafficLightColor
static let yellow: TrafficLightColor
static let green: TrafficLightColor
}
Expected Results:
According to the documentation, NS_STRING_ENUM should be ported to Swift as an enum.
Actual Results:
Although the documentation says NS_STRING_ENUM should be ported to swift as an enum. It actually gets ported over as a struct
Version:
Xcode 8.0 to 8.1
Notes:
Since NS_STRING_ENUM currently does not create an enum, it is not possible to create an exhaustive list in a switch statement. All switch statements evaluating it will need to end with a default case.
var trafficColor = TrafficLightColor.red
switch trafficColor {
case .red: ()
case .yellow: ()
case .green: ()
default🙁)
// Default case is required. If it was an enum, then all states would have been covered.
}
Notes:
I have 3 sources that claim an NS_STRING_ENUM should produce an enum:
It turned out to be neither feasible nor correct to treat NS_STRING_ENUM as a Swift enum. @milseman, can you write up an update to the proposal? (I believe there's already a Radar on the Apple docs folks to update the documentation.)
I'm a little disappointed that NS_STRING_ENUM turned out to be impossible; its was one of the coolest features of Swift3. @belkadan would the reverse be feasible? By reverse Meaning an enum-string-like swift object can be converted to something for objective-c ?
Environment
Xcode 8 to Xcode 8.1
Additional Detail from JIRA
md5: 3337da0d174cba9207af3de875bc072c
Issue Description:
I believe this is a Huge bug. In Xcode 8 we were given NS_STRING_ENUM and NS_EXTENSIBLE_STRING_ENUM. The former is suppose to turn objective-c Global strings into swift enum strings while the latter turns objective-c Global strings into swift structs with constant variable strings.
Steps to Reproduce:
Suppose we have the following objective-c header file
// traffic.h
typedef NSString * TrafficLightColor NS_STRING_ENUM;
static TrafficLightColor const TrafficLightColorRed = @"Red";
static TrafficLightColor const TrafficLightColorYellow = @"Yellow";
static TrafficLightColor const TrafficLightColorGreen = @"Green";
When we try to access TrafficLightColor in swift, it is treated as a struct. below is the Generated interface produced by Xcode:
struct TrafficLightColor : RawRepresentable, _SwiftNewtypeWrapper, Equatable, Hashable, Comparable, _ObjectiveCBridgeable {
static let red: TrafficLightColor
static let yellow: TrafficLightColor
static let green: TrafficLightColor
}
Expected Results:
According to the documentation, NS_STRING_ENUM should be ported to Swift as an enum.
Actual Results:
Although the documentation says NS_STRING_ENUM should be ported to swift as an enum. It actually gets ported over as a struct
Version:
Xcode 8.0 to 8.1
Notes:
Since NS_STRING_ENUM currently does not create an enum, it is not possible to create an exhaustive list in a switch statement. All switch statements evaluating it will need to end with a default case.
var trafficColor = TrafficLightColor.red
switch trafficColor {
case .red: ()
case .yellow: ()
case .green: ()
default🙁)
// Default case is required. If it was an enum, then all states would have been covered.
}
Notes:
I have 3 sources that claim an NS_STRING_ENUM should produce an enum:
The text was updated successfully, but these errors were encountered: