Check Boxes in AppKit

Check boxes in AppKit are realized with buttons. The API reads kind of weird, so here’s a simple subclass:

class CheckBox: NSButton {    
    var checked: Bool {
        get { return state == NSOnState }
        set { state = newValue ? NSOnState : NSOffState }

Now it’s easy to use checkbox.checked = true. I’d even consider check() and uncheck() methods if I used this in many places to reduce the noise and clarify what’s going on.

Receive new .