I've got an enum with an associated value, ChatItemType
:
enum ChatItemType {
case message(ChatBubbleType)
case log
case timestamp
}
I'm doing a comparison like this in an if-statement:
if case .log = givenType {
return true
} else if case .timestamp = givenType {
return true
} else {
return false
}
It obviously makes sense to combine the first and second statement as they both return true
. But using ||
the way I'd expect it to be used seems to give me a syntax error:
if case .log = givenType || case .timestamp = givenType
I'm aware that I could just check for the .message
type instead and else return true
, but more ChatItemType
s are likely to be added in the future, so I'd like to still know how to properly combine comparisons.
I'm finding it hard to find the answer to this online mainly because I'm not sure of the right terminology to refer to these concepts. Any guidance there appreciated, too.