关闭

Write custom NSTextField class to work with Measurement in Swift

该项目收到5 来自天才威客的竞标,平均竞标价格为$82 USD

为像这样的项目获取免费报价
雇主工作
项目预算
$10 - $30 USD
全部竞标
5
项目描述

See stackoverflow question here: [url removed, login to view]

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()

[url removed, login to view] = .medium

[url removed, login to view] = .providedUnit

let area = Measurement<UnitArea>( value: [url removed, login to view], unit: .squareInches)

let editInput = NSTextFieldCell

[url removed, login to view] = area

[url removed, login to view] = areaFormatter

This displays something like

[url removed, login to view] in^2

The problem starts when I want to read this back in with

var inputArea = [url removed, login to view] 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 = [url removed, login to view] as! Measurement<UnitArea>

so this gets displayed

[url removed, login to view] in^2

but only the [url removed, login to view] can be edited.

在寻找赚取金钱的机会?

  • 设定您的预算和时间框架
  • 大致描述您的建议方案
  • 为您的工作领取工资

雇用同样在该项目上竞标的威客

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online