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 the lhs and rhs are isEqual, then this returns the result of adding the value of each ValidatedMeasurement. If they are not equal, then this will convert both to the base unit of the Dimension and return the result as a ValidatedMeasurement 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 the lhs and rhs are ==, then this returns the result of subtracting the value of each ValidatedMeasurement. If they are not equal, then this will convert both to the base unit of the Dimension and return the result as a ValidatedMeasurement 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.

    Precondition

    The unit of lhs and rhs must be isEqual and valid must be equal.

    Declaration

    Swift

    public static func + (lhs: ValidatedMeasurement<UnitType>, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>

    Return Value

    A measurement of value lhs.value + rhs.value and unit lhs.unit.

  • Subtract two measurements of the same Unit.

    Precondition

    The unit of lhs and rhs must be isEqual and valid must be equal.

    Declaration

    Swift

    public static func - (lhs: ValidatedMeasurement<UnitType>, rhs: ValidatedMeasurement<UnitType>) -> ValidatedMeasurement<UnitType>

    Return Value

    A measurement of value lhs.value - rhs.value and unit lhs.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 as lhs.

  • 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 as rhs.

  • 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 as lhs.

  • 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 as rhs.

  • Compare two measurements of the same Dimension.

    If lhs.unit == rhs.unit, returns lhs.value == rhs.value. Otherwise, converts rhs to the same unit as lhs 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 the lhs is less than the rhs 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.