NOT condition in ‘if case’ statement

This “answer” is nothing more than writing your awkward solution in a more compact manner. If you only care about the case when a value is not of a certain enum value, you could write it like this all in one line with the else immediately following the empty then clause:

enum E {
    case A, B(String), C(Int)
}

let a: E = .B("Hello")

if case .A = a {} else {
    print("not an A")
}

if case .B = a {} else {
    print("not a B")
}

if case .C = a {} else {
    print("not a C")
}

Leave a Comment

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