HealthSampleUnit

public struct HealthSampleUnit<MeasurementType> : RawRepresentable, Encodable where MeasurementType : HealthMeasurementType

The unit of a Health sample, such as “liters” or “fl oz (US)”.

  • The corresponding value of the raw type.

    Declaration

    Swift

    public let rawValue: String
  • Creates a new instance with the specified raw value.

    Declaration

    Swift

    public init(rawValue: String)

    Parameters

    rawValue

    The raw value to use for the new instance.

  • Creates a new instance with the specified raw value.

    Declaration

    Swift

    public init(_ rawValue: String)

    Parameters

    rawValue

    The raw value to use for the new instance.

  • Encodes this value into the given encoder.

    Throws

    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.

Available where MeasurementType == HealthMeasurement.Count

  • The “count” sample unit in the Health app.

    Declaration

    Swift

    public static var count: HealthSampleUnit { get }

Available where MeasurementType == HealthMeasurement.Liquid

  • The “liters” sample unit in the Health app.

    Declaration

    Swift

    public static var liters: HealthSampleUnit { get }