How in Swift specify type constraint to be enum?

enum SomeEnum: Int {
    case One, Two, Three
}

class SomeClass<E: RawRepresentable where E.RawValue == Int>{
    func doSomething(e: E) {
        print(e.rawValue)
    }
}

class SomeEnumClass : SomeClass<SomeEnum> {

}

or directly

class SomeOtherClass{
    func doSomething<E: RawRepresentable where E.RawValue == Int>(e: E) {
        print(e.rawValue)
    }
}

UPDATE for swift3:

enum SomeEnum: Int {
    case One, Two, Three
}

class SomeClass<E: RawRepresentable> where E.RawValue == Int {
    func doSomething(e: E) {
        print(e.rawValue)
    }
}

class SomeEnumClass : SomeClass<SomeEnum> {

}

resp.

class SomeOtherClass{
    func doSomething<E: RawRepresentable>(e: E) where E.RawValue == Int {
        print(e.rawValue)
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)