ValidatedMeasurement
@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
public struct ValidatedMeasurement<UnitType> : Comparable, Equatable where UnitType : Unit
A ValidatedMeasurement
is a model type that holds a Double
value associated with a Unit
.
ValidatedMeasurement
act the same way Measurement
does, but provides feedback on validity of data
ValidatedMeasurements support a large set of operators, including +
, -
, *
, /
, and a full set of comparison operators.
-
The unit component of the
ValidatedMeasurement
.Declaration
Swift
public let unit: UnitType
-
The value component of the
ValidatedMeasurement
.Declaration
Swift
public var value: Double
-
The validity of the
ValidatedMeasurement
.Declaration
Swift
public var valid: Bool
-
Create a
ValidatedMeasurement
given a specified value and unit.Declaration
Swift
public init(value: Double, valid: Bool, unit: UnitType)
-
Undocumented
Declaration
Swift
public var hashValue: Int { get }
-
Declaration
Swift
public var description: String { get }
-
Declaration
Swift
public var debugDescription: String { get }
-
Declaration
Swift
public var customMirror: Mirror { get }
-
Returns a new measurement created by converting to the specified unit.
Declaration
Swift
public func converted(to otherUnit: UnitType) -> ValidatedMeasurement<UnitType>
Parameters
otherUnit
A unit of the same
Dimension
.Return Value
A converted measurement.
-
Converts the measurement to the specified unit.
Declaration
Swift
public mutating func convert(to otherUnit: UnitType)
Parameters
otherUnit
A unit of the same
Dimension
. -
Add two measurements of the same Dimension.
If the
unit
of thelhs
andrhs
areisEqual
, then this returns the result of adding thevalue
of eachValidatedMeasurement
. If they are not equal, then this will convert both to the base unit of theDimension
and return the result as aValidatedMeasurement
of that base unit.Declaration
Swift
public static func + (lhs: ValidatedMeasurement<UnitType>, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>
Return Value
The result of adding the two measurements.
-
Subtract two measurements of the same Dimension.
If the
unit
of thelhs
andrhs
are==
, then this returns the result of subtracting thevalue
of eachValidatedMeasurement
. If they are not equal, then this will convert both to the base unit of theDimension
and return the result as aValidatedMeasurement
of that base unit.Declaration
Swift
public static func - (lhs: ValidatedMeasurement<UnitType>, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>
Return Value
The result of adding the two measurements.
-
Add two measurements of the same Unit.
Declaration
Swift
public static func + (lhs: ValidatedMeasurement<UnitType>, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>
Return Value
A measurement of value
lhs.value + rhs.value
and unitlhs.unit
. -
Subtract two measurements of the same Unit.
Declaration
Swift
public static func - (lhs: ValidatedMeasurement<UnitType>, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>
Return Value
A measurement of value
lhs.value - rhs.value
and unitlhs.unit
. -
Multiply a measurement by a scalar value.
Declaration
Swift
public static func * (lhs: ValidatedMeasurement<UnitType>, rhs: Double) -> ValidatedMeasurement<UnitType>
Return Value
A measurement of value
lhs.value * rhs
with the same unit aslhs
. -
Multiply a scalar value by a measurement.
Declaration
Swift
public static func * (lhs: Double, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>
Return Value
A measurement of value
lhs * rhs.value
with the same unit asrhs
. -
Divide a measurement by a scalar value.
Declaration
Swift
public static func / (lhs: ValidatedMeasurement<UnitType>, rhs: Double) -> ValidatedMeasurement<UnitType>
Return Value
A measurement of value
lhs.value / rhs
with the same unit aslhs
. -
Divide a scalar value by a measurement.
Declaration
Swift
public static func / (lhs: Double, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>
Return Value
A measurement of value
lhs / rhs.value
with the same unit asrhs
. -
Compare two measurements of the same
Dimension
.If
lhs.unit == rhs.unit
, returnslhs.value == rhs.value
. Otherwise, convertsrhs
to the same unit aslhs
and then compares the resulting values.Declaration
Swift
public static func == <LeftHandSideType, RightHandSideType>(lhs: ValidatedMeasurement<LeftHandSideType>, rhs: ValidatedMeasurement<RightHandSideType>) -> Bool where LeftHandSideType : Unit, RightHandSideType : Unit
Return Value
true
if the measurements are equal. -
Compare two measurements of the same
Unit
.Declaration
Swift
public static func < <LeftHandSideType, RightHandSideType>(lhs: ValidatedMeasurement<LeftHandSideType>, rhs: ValidatedMeasurement<RightHandSideType>) -> Bool where LeftHandSideType : Unit, RightHandSideType : Unit
Return Value
true
if the measurements can be compared and thelhs
is less than therhs
converted value.
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
Encodes this value into the given encoder.
If the value fails to encode anything,
encoder
will encode an empty keyed container in its place.This function throws an error if any values are invalid for the given encoder’s format.
Declaration
Swift
public func encode(to encoder: Encoder) throws
Parameters
encoder
The encoder to write data to.