如何动态初始化swift枚举实例

时间:2017-02-28 12:06:05

标签: swift

我们有

enum Foo: Int {
    case A
    case B
    case C
}

enum Bar: Int {
    case D
    case E
    case F
}

我们可以做到

let i = 0;
let typeOfEnum = Foo.self;
let ins = typeOfEnum.init(rawValue: 1)

但是如何编写泛型函数来初始化枚举实例,其中原始值是Int(或其他)

T newEnumInstance(theType : T.Type , rawValue: Int) {
    ???????
}

0 个答案:

没有答案