Write custom NSTextField class to work with Measurement in Swift
$10-30 USD
Cerrado
Publicado hace más de 7 años
$10-30 USD
Pagado a la entrega
See stackoverflow question here: [login to view URL]
Looking for a custom NSTextField class (or NSTextFieldCell class) where I can read and write measurements to where the user can not edit the measurement text.
I want to be able to nicely use a Measurement and MeasurementFormatter for output and input with a NSTextFieldCell.
I am able to display the measurement correctly with...
let areaFormatter = MeasurementFormatter()
[login to view URL] = .medium
[login to view URL] = .providedUnit
let area = Measurement<UnitArea>( value: 123.43, unit: .squareInches)
let editInput = NSTextFieldCell
[login to view URL] = area
[login to view URL] = areaFormatter
This displays something like
123.43 in^2
The problem starts when I want to read this back in with
var inputArea = [login to view URL] as! Measurement<UnitArea>
I think because the get Object value of the Measurement Formatter is not defined.
open func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool
Is my understanding correct? Are there any examples in Swift where this function has been defined for measurements?
Right now the user can edit the entire string including the text in the units. Is there a good way to block the units in the NSTextFieldCell? I would like the user to be able to edit the number but not the units and then return the measurement with
var inputArea = [login to view URL] as! Measurement<UnitArea>
so this gets displayed
123.43 in^2
but only the 123.43 can be edited.