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
ValidatedMeasurementgiven 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
otherUnitA 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
otherUnitA unit of the same
Dimension. -
Add two measurements of the same Dimension.
If the
unitof thelhsandrhsareisEqual, then this returns the result of adding thevalueof eachValidatedMeasurement. If they are not equal, then this will convert both to the base unit of theDimensionand return the result as aValidatedMeasurementof 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
unitof thelhsandrhsare==, then this returns the result of subtracting thevalueof eachValidatedMeasurement. If they are not equal, then this will convert both to the base unit of theDimensionand return the result as aValidatedMeasurementof 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.valueand 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.valueand 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 * rhswith 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.valuewith 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 / rhswith 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.valuewith the same unit asrhs. -
Compare two measurements of the same
Dimension.If
lhs.unit == rhs.unit, returnslhs.value == rhs.value. Otherwise, convertsrhsto the same unit aslhsand then compares the resulting values.Declaration
Swift
public static func == <LeftHandSideType, RightHandSideType>(lhs: ValidatedMeasurement<LeftHandSideType>, rhs: ValidatedMeasurement<RightHandSideType>) -> Bool where LeftHandSideType : Unit, RightHandSideType : UnitReturn Value
trueif 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 : UnitReturn Value
trueif the measurements can be compared and thelhsis less than therhsconverted value.
-
Declaration
Swift
public init(from decoder: Decoder) throws -
Encodes this value into the given encoder.
If the value fails to encode anything,
encoderwill 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) throwsParameters
encoderThe encoder to write data to.