Value matching Bool or Int #45
-
QLab is a great application but is somewhat simplistic in its OSC argument type support: String, Int and Float. Is there a concise way to handle a message that could have a Bool or Int (check for non-zero) value? My first thought was to use masked with optionals, but it throws: let (flag, num) = try message.values.masked(Bool?.self, Int32?.self) and instead have a verbose loop over values: for value in message.values {
switch value {
case let val as Bool:
_ = val
continue
case let val as Int32:
_ = val != 0
continue
default:
break
}
} Is there a better way to handle this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I just ran into this last week actually. There is a metatype called My solution was a two-step cascade to first test the value mask using if let (flag, num) = try? message.values.masked(Bool.self, Int32.self) {
// first arg is Bool
} else {
let (flag, num) = try message.values.masked(AnyOSCNumberValue.self, Int32.self)
let flagBool: Bool = flag.intValue == 1
} I could envision expanding Note that you only want to make a value type Optional in the |
Beta Was this translation helpful? Give feedback.
@DoubleBaroness I have released 1.2.1 which now allows
AnyOSCNumberValue
to match against an OSC bool value.That means only a single mask call is needed: