[swift-evolution] Proposed changes to SE-0033 Import Objective-C Constants as Swift Types

Ben Rimmington me at benrimmington.com
Mon Jun 6 21:18:41 CDT 2016


Michael Ilseman wrote:

> The biggest issue with the proposal as written is with importing a typedef
> as an enum. Enums do not allow us to control the underlying storage,
> and thus we would constantly be paying a bridging cost in its use.
> [...]
> The second issue concerns importing bridged typedefs, e.g. NSString.
> In that case, we want the underlying storage to be NSString,
> but present it as a String to the users.

Could you import __attribute__((swift_wrapper(enum)) constants as follows:

public enum HKQuantityTypeIdentifier : String {
    case bodyMassIndex
    case bodyFatPercentage
    case height
    case bodyMass
    case leanBodyMass

    private static let _bodyMassIndex:     NSString
    private static let _bodyFatPercentage: NSString
    private static let _height:            NSString
    private static let _bodyMass:          NSString
    private static let _leanBodyMass:      NSString
}

-- Ben




More information about the swift-evolution mailing list