Generic Structure

Measurement

A numeric quantity labeled with a unit of measure, with support for unit conversion and unit-aware calculations.

Overview

Measurements support a large set of operators, including +, -, *, /, and a full set of comparison operators.

Topics

Creating a Measurement

init(value: Double, unit: UnitType)

Create a Measurement given a specified value and unit.

Accessing the Value and Units

let unit: UnitType

The unit component of the Measurement.

var value: Double

The value component of the Measurement.

Converting to Other Units

func convert(to: UnitType)

Converts the measurement to the specified unit.

func converted(to: UnitType)

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

Operating on a Measurement

static func != (Measurement<UnitType>, Measurement<UnitType>)

Returns a Boolean value indicating whether two values are not equal.

static func * (Double, Measurement<UnitType>)

Multiply a scalar value by a measurement.

static func * (Measurement<UnitType>, Double)

Multiply a measurement by a scalar value.

static func ... (Measurement<UnitType>)

Returns a partial range extending upward from a lower bound.

static func ... (Measurement<UnitType>)

Returns a partial range up to, and including, its upper bound.

static func ..< (Measurement<UnitType>)

Returns a partial range up to, but not including, its upper bound.

static func / (Double, Measurement<UnitType>)

Divide a scalar value by a measurement.

static func / (Measurement<UnitType>, Double)

Divide a measurement by a scalar value.

static func <= (Measurement<UnitType>, Measurement<UnitType>)

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func > (Measurement<UnitType>, Measurement<UnitType>)

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func >= (Measurement<UnitType>, Measurement<UnitType>)

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

Describing a Measurement

var description: String

A textual description of the measurement.

var debugDescription: String

A textual description of the measurement suitable for debugging.

var customMirror: Mirror

A mirror that reflects the date interval.

var hashValue: Int

The computed hash value for the date interval.

Using Reference Types

class NSMeasurement

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.

typealias Measurement.ReferenceType

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

Instance Methods

Operator Functions

static func ... (Measurement<UnitType>, Measurement<UnitType>)

Returns a closed range that contains both of its bounds.

static func ..< (Measurement<UnitType>, Measurement<UnitType>)

Returns a half-open range that contains its lower bound but not its upper bound.

See Also

First Steps

class Unit

An abstract class representing a unit of measure.

class Dimension

An abstract class representing a dimensional unit of measure.