Ethan Ethan - 5 months ago 77
Swift Question

Checking bitmask in Swift

Tried the code below, doesn't compile

if button.keyEquivalentModifierMask & NSEventModifierFlags.CommandKeyMask != 0 {

What's a proper way to check for bitmasks in Swift?


keyEquivalentModifierMask is a Int, whereas NSEventModifierFlags.CommandKeyMask is an enum-like with UInt raw value, so you have to read the rawValue out of it and convert keyEquivalentModifierMask to Uint:

if UInt(button.keyEquivalentModifierMask) & NSEventModifierFlags.CommandKeyMask.rawValue > 0 {