How to check the case of an enum while ignoring the associated value?
The below is what I used but it gives an error...
enum Example {
case one(value: String)
case two(otherValue: Int)
}
var test = Example.one(value: "A String")
if test == Example.one { // Gives Error
// Do Something
}
Duplicate question is overly complex.
Use the below if case
statement instead:
enum Example {
case one(value: String)
case two(otherValue: Int)
}
var test = Example.one(value: "A String")
if case Example.one(value: _) = test { // Works
// Do Something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With