Since my last question I went on trying to make a ValueTransformer transform the values of a NSSlider into Integer.
Background: I have an NSSlider which is bound to Shared User Defaults Controller. A textlabel is also bound to the Shared User Defaults Controller with the same key. I need the textfield to only show Int.
Now my code looks like this:
class IntegerTransformmer: ValueTransformer {
override class func transformedValueClass() -> AnyClass {
return NSNumber.self
}
override class func allowsReverseTransformation() -> Bool {
return true
}
// as far as I know, here is an override function required. But doing override in the following line, i´m getting error.
func transformedValue(value: Any?) -> Int? {
let int = value as! Int
return int
}
}
For both, NSSlider and the label I set in bindingsInspector the the Value Transformer on IntegerTransformmer.
In AppDelegate I initialize the ValueTransformer like this:
override class func initialize() {
let newTransformer = IntegerTransformmer()
ValueTransformer.setValueTransformer(newTransformer, forName: NSValueTransformerName(rawValue: "IntegerTransformmer"))
}
The building works without error, but in my label, I´m still getting DoubleValues.
Why I´m not allowed to make transformedValue(value: Any?)as override?
Is this the reason why it´s not working?
Help of any kind would be much appreciated.