Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.

2015-04-07

Swift extensions: NSEventModifierFlags functions isSet and isNotSet

This extension makes working with the NSEventModifierFlags a little easier by hiding the verbose testing code inside a test function.

extension NSEventModifierFlags {
    
    func isSet(bit: NSEventModifierFlags) -> Bool {
        return self & bit == bit
    }
    
    func isNotSet(bit: NSEventModifierFlags) -> Bool {
        return !isSet(bit)
    }

}

After this the code to test for a modifier becomes very readable:

if theEvent.modifierFlags.isSet(.ShiftKeyMask) { ... }


Happy coding

Did this help?, then please help out a small independent.
If you decide that you want to make a small donation, you can do so by clicking this
link: a cup of coffee ($2) or use the popup on the right hand side for different amounts.
Payments will be processed by PayPal, receiver will be sales at balancingrock dot nl
Bitcoins will be gladly accepted at: 1GacSREBxPy1yskLMc9de2nofNv2SNdwqH

We don't get the world we wish for... we get the world we pay for.

No comments:

Post a Comment