I followed my understanding of how to expose a property of an NSSlider subclass in Interface Builder but it is not showing up. I want to be able to bind the property in a viewcontroller through Interface Builder to track the movement of the slider better.
Here's the subclass
@objc class GJSlider: NSSlider {
@objc dynamic var sliderMouseEnd: Bool = false
override var exposedBindings: [NSBindingName] {
get {
var temp = super.exposedBindings
temp.append(NSBindingName(rawValue: "sliderMouseEnd"))
return temp
}
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
GJSlider.exposeBinding(NSBindingName(rawValue: "sliderMouseEnd"))
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override class func valueClassForBinding(_ binding: NSBindingName) -> AnyClass? {
if binding == NSBindingName(rawValue: "sliderMouseEnd") {
return Optional<Bool>.self as! AnyClass
} else {
return super.valueClassForBinding(binding)
}
}
}
After reviewing the documentation more, the NSKeyValueBindingCreation says:
NSView subclasses can expose additional key-value-coding/key-value-observing compliant properties as bindings by calling the class method exposeBinding(_:) for each of the properties. This is typically done in the class’s initialize method. By exposing the bindings that an object supports and creating an Interface Builder palette, you can make instances of your own classes bindable in Interface Builder.
So I guess the important point is how do I create an "Interface Builder palette"