An object representing a numeric quantity with a unit of measure that bridges to Measurement; use NSMeasurement when you need reference semantics or other Foundation-specific behavior.


class NSMeasurement : NSObject


An NSMeasurement object represents a quantity and unit of measure. The NSMeasurement class provides a programmatic interface to converting measurements into different units, as well as calculating the sum or difference between two measurements.

NSMeasurement objects are initialized with an Unit object and double value. NSMeasurement objects are immutable, and cannot be changed after being created.

You can use the MeasurementFormatter class to create localized string representations of NSMeasurement objects.


Creating Measurements

init(doubleValue: Double, unit: Unit)

Initializes a new measurement with a specified double-precision floating-point value and unit.

Accessing Unit and Value

var unit: Unit

The unit of measure.

var doubleValue: Double

The measurement value, represented as a double-precision floating-point number.

Converting to Other Units

func canBeConverted(to: Unit) -> Bool

Indicates whether the measurement can be converted to the given unit.

func converting(to: Unit) -> Measurement<Unit>

Returns a measurement created by converting the receiver to the specified unit.

Operating on Measurements

func adding(Measurement<Unit>) -> Measurement<Unit>

Returns a new measurement by adding the receiver to the specified measurement.

func subtracting(Measurement<Unit>) -> Measurement<Unit>

Returns a new measurement by subtracting the specified measurement from the receiver.


Inherits From

See Also

Using Reference Types

typealias Measurement.ReferenceType

An alias for this value type's equivalent reference type.