【问题标题】:Objective-C compatible Swift enum with NSUIntegerMaxObjective-C 兼容 Swift 枚举与 NSUIntegerMax
【发布时间】:2017-01-26 14:38:24
【问题描述】:

我正在将一些代码从 Objective-C 翻译成 Swift。

typedef NS_ENUM(NSUInteger, SomeType) {
    SomeTypeZero = 0,
    SomeTypeOne = 1,
    SomeTypeMax = NSUIntegerMax
};

但是 UInt.max 给了我一个编译器错误:“枚举大小写的原始值必须是文字。”

@objc enum SomeType: UInt {
    case zero = 0
    case one = 6
    case max = UInt.max
}

那么这里发生了什么,我该如何翻译它,并具有向后兼容性?

【问题讨论】:

标签: objective-c swift enums uint


【解决方案1】:

UInt.max 是在运行时定义的值。然而,作为枚举的值,需要在编译时定义。

【讨论】:

    猜你喜欢
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多