終了

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