I have an error and I need to check if it's NOT a specific case of MyError:
enum MyError {
case one(description: String)
case two(description: String)
case three(description: String)
(...)
}
I can easily check if an error
variable is a specific case of MyError:
if case MyError.one = error {
// this is definitely error MyError.one
}
How can I make sure it's NOT a specific case?
if (...) { // something like: !(case MyError.one = error)
// this is any other case but NOT MyError.one
}
I know I can do this with the guard
keyword or if-else
but I'm wondering if there is a more elegant solution (as guard needs a return
):
guard case MyError.one = error else {
// this is any other case but NOT MyError.one
return
}