StructureFoundation5.9.0
Measurement
A Measurement
is a model type that holds a Double
value associated with a Unit
.
- iOS
- 10.0+
- macOS
- 10.12+
- tvOS
- 10.0+
- watchOS
- 3.0+
struct Measurement<UnitType> where UnitType : Unit
Measurements support a large set of operators, including +
, -
, *
, /
, and a full set of comparison operators.
Citizens in Foundation
Conformances
protocol Comparable
A type that can be compared using the relational operators
<
,<=
,>=
, and>
.protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol ReferenceConvertible
Decorates types which are backed by a Foundation reference type.
Members
init(value: Double, unit: UnitType
) Create a
Measurement
given a specified value and unit.let unit: UnitType
The unit component of the
Measurement
.var value: Double
The value component of the
Measurement
.func hash(into: inout Hasher
) typealias ReferenceType
Features
static func != (Self, Self
) -> Bool static func ... (Self
) -> PartialRangeFrom<Self> Returns a partial range extending upward from a lower bound.
static func ... (Self
) -> PartialRangeThrough<Self> Returns a partial range up to, and including, its upper bound.
static func ... (Self, Self
) -> ClosedRange<Self> Returns a closed range that contains both of its bounds.
static func ..< (Self
) -> PartialRangeUpTo<Self> Returns a partial range up to, but not including, its upper bound.
static func ..< (Self, Self
) -> Range<Self> Returns a half-open range that contains its lower bound but not its upper bound.
Citizens in Foundation
where UnitType:Unit
Conformances
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol CustomReflectable
A type that explicitly supplies its own mirror.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
Members
init(from: Decoder
) throws var customMirror: Mirror
var debugDescription: String
var description: String
static func * (Measurement
<UnitType>, Double) -> Measurement<UnitType> Multiply a measurement by a scalar value.
static func * (Double, Measurement
<UnitType>) -> Measurement<UnitType> Multiply a scalar value by a measurement.
static func + (Measurement
<UnitType>, Measurement<UnitType>) -> Measurement<UnitType> Add two measurements of the same Unit.
static func - (Measurement
<UnitType>, Measurement<UnitType>) -> Measurement<UnitType> Subtract two measurements of the same Unit.
static func / (Measurement
<UnitType>, Double) -> Measurement<UnitType> Divide a measurement by a scalar value.
static func / (Double, Measurement
<UnitType>) -> Measurement<UnitType> Divide a scalar value by a measurement.
static func < <LeftHandSideType, RightHandSideType>(Measurement
<LeftHandSideType>, Measurement<RightHandSideType>) -> Bool Compare two measurements of the same
Unit
.static func == <LeftHandSideType, RightHandSideType>(Measurement
<LeftHandSideType>, Measurement<RightHandSideType>) -> Bool Compare two measurements of the same
Dimension
.func encode(to: Encoder
) throws
Features
Citizens in Foundation
where UnitType:Dimension
Members
static func + (Measurement
<UnitType>, Measurement<UnitType>) -> Measurement<UnitType> Add two measurements of the same Dimension.
static func - (Measurement
<UnitType>, Measurement<UnitType>) -> Measurement<UnitType> Subtract two measurements of the same Dimension.
func convert(to: UnitType
) Converts the measurement to the specified unit.
func converted(to: UnitType
) -> Measurement<UnitType> Returns a new measurement created by converting to the specified unit.