What's New / Health, Sensors & Motion

What's new in HealthKit

+19 NewiOS · macOS · watchOS · visionOS

HealthKit is Apple's framework for storing and sharing health and fitness data across apps on iOS, watchOS, and related platforms. It has APIs for sample types, workouts, and live workout sessions.

19 new APIs, no deprecations or removals. Workout zones add HKWorkoutZone, HKWorkoutZoneConfiguration, HKWorkoutZoneDuration, HKWorkoutZoneGroup, HKLiveWorkoutZoneUpdate, and a new HKLiveWorkoutBuilderDelegate.workoutBuilder callback. Menopause data adds the HKCategoryValueMenopausalState enum plus the bleedingAfterMenopause and menopausalState category type identifiers.

New

19
enum

HKCategoryValueMenopausalState

NewiOSmacOSwatchOS
public enum HKCategoryValueMenopausalState : Int, @unchecked Sendable
Declaration
public enum HKCategoryValueMenopausalState : Int, @unchecked Sendable {

    case menopause = 1

    case perimenopause = 2

    case none = 3
}
extension

HKCategoryValueMenopausalState

NewiOSmacOSvisionOSwatchOS
extension HKCategoryValueMenopausalState : HKCategoryValuePredicateProviding
Declaration
extension HKCategoryValueMenopausalState : HKCategoryValuePredicateProviding {
}
extension

HKLiveWorkoutZoneUpdate

NewiOSwatchOS
extension HKLiveWorkoutZoneUpdate
Declaration
@nonobjc extension HKLiveWorkoutZoneUpdate {

    /// The complete zone group containing all current duration data.
    @nonobjc final public var zoneGroup: HKWorkoutZoneGroup? { get }

    /// The new zone duration that has just been entered, or nil if no zone is active.
    @nonobjc final public var previousZoneDuration: HKWorkoutZoneDuration? { get }

    /// The new zone duration that has just been entered, or nil if no zone is active.
    @nonobjc final public var currentZoneDuration: HKWorkoutZoneDuration? { get }
}
extension

HKWorkout

NewiOSmacOSvisionOSwatchOS
extension HKWorkout
Declaration
extension HKWorkout {

    /// A dictionary mapping quantity types to their corresponding zone groups for this workout.
    public var zoneGroupsByType: [HKQuantityType : HKWorkoutZoneGroup]? { get }

    public func zoneGroup(for quantityType: HKQuantityType) -> HKWorkoutZoneGroup?
}
extension

HKWorkoutActivity

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutActivity
Declaration
extension HKWorkoutActivity {

    /// A dictionary mapping quantity types to their corresponding zone groups for this workout activity.
    public var zoneGroupsByType: [HKQuantityType : HKWorkoutZoneGroup]? { get }

    public func zoneGroup(for quantityType: HKQuantityType) -> HKWorkoutZoneGroup?
}
extension

HKWorkoutBuilder

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutBuilder
Declaration
extension HKWorkoutBuilder {

    /// Sets the zone configuration for the specified quantity type for this workout.
    /// In order to provide a custom workout zone configuration, this must be called before beginning collection on the builder.
    /// If a custom configuration is not provided, the user's preferred workout zone configuration will be used for zone calculations.
    /// - Parameter configuration: The zone configuration to use. Setting to `nil` will remove any custom configuration and use the preferred zone configuration for the quantity type.
    /// - Parameter quantityType: The quantity type to apply the configuration to.
    /// - Throws: An error if the configuration cannot be set or is incompatible with the quantity type.
    public func setCustomZoneConfiguration(_ configuration: HKWorkoutZoneConfiguration?, for quantityType: HKQuantityType) async throws

    /// Returns the zone configuration being used for the specified quantity type in this workout.
    /// If a custom configuration has been set via `setZoneConfiguration(_:for:)`, that configuration is returned.
    /// Otherwise, this method fetches and returns the user's preferred workout zone configuration from the health store.
    /// - Parameter quantityType: The quantity type to retrieve the configuration for.
    /// - Returns: The active zone configuration, or nil if no custom configuration has been set and the user has no preferred configuration for the quantity type.
    /// - Throws: An error if the configuration cannot be retrieved.
    public func zoneConfiguration(for quantityType: HKQuantityType) async throws -> HKWorkoutZoneConfiguration?

    /// Returns the current zone group for the specified quantity type, including real-time duration calculations.
    /// - Parameter quantityType: The quantity type to retrieve zone information for.
    /// - Returns: The zone group with current time-in-zone data, or nil if no zone information is available.
    public func zoneGroup(for quantityType: HKQuantityType) -> HKWorkoutZoneGroup?
}
struct

HKWorkoutZone

NewiOSmacOSvisionOSwatchOS
public struct HKWorkoutZone : Sendable
Declaration
public struct HKWorkoutZone : Sendable {

    /// The zero-based index of the zone within the containing `HKWorkoutZoneConfiguration`, ordered from lowest to highest threshold.
    public let index: Int

    /// The minimum threshold for this zone. If nil, the zone has no lower bound.
    public var minimum: HKQuantity? { get }

    /// The maximum threshold for this zone. If nil, the zone has no upper bound.
    public var maximum: HKQuantity? { get }
}
struct

HKWorkoutZoneConfiguration

NewiOSmacOSvisionOSwatchOS
public struct HKWorkoutZoneConfiguration : Sendable
Declaration
public struct HKWorkoutZoneConfiguration : Sendable {

    /// The type of configuration used to generate the zones.
    public enum Source : Codable, Sendable {

        /// Zones automatically generated by the system.
        case system

        /// Zones manually configured by the user in Health Settings.
        case user

        /// Zones provided by a third-party app for a specific workout.
        case app

        /// Returns a Boolean value indicating whether two values are equal.
        ///
        /// Equality is the inverse of inequality. For any values `a` and `b`,
        /// `a == b` implies that `a != b` is `false`.
        ///
        /// - Parameters:
        ///   - lhs: A value to compare.
        ///   - rhs: Another value to compare.
        public static func == (a: HKWorkoutZoneConfiguration.Source, b: HKWorkoutZoneConfiguration.Source) -> Bool

        /// 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.
        ///
        /// - Parameter encoder: The encoder to write data to.
        public func encode(to encoder: any Encoder) throws

        /// Hashes the essential components of this value by feeding them into the
        /// given hasher.
        ///
        /// Implement this method to conform to the `Hashable` protocol. The
        /// components used for hashing must be the same as the components compared
        /// in your type's `==` operator implementation. Call `hasher.combine(_:)`
        /// with each of these components.
        ///
        /// - Important: In your implementation of `hash(into:)`,
        ///   don't call `finalize()` on the `hasher` instance provided,
        ///   or replace it with a different instance.
        ///   Doing so may become a compile-time error in the future.
        ///
        /// - Parameter hasher: The hasher to use when combining the components
        ///   of this instance.
        public func hash(into hasher: inout Hasher)

        /// The hash value.
        ///
        /// Hash values are not guaranteed to be equal across different executions of
        /// your program. Do not save hash values to use during a future execution.
        ///
        /// - Important: `hashValue` is deprecated as a `Hashable` requirement. To
        ///   conform to `Hashable`, implement the `hash(into:)` requirement instead.
        ///   The compiler provides an implementation for `hashValue` for you.
        public var hashValue: Int { get }

        /// Creates a new instance by decoding from the given decoder.
        ///
        /// This initializer throws an error if reading from the decoder fails, or
        /// if the data read is corrupted or otherwise invalid.
        ///
        /// - Parameter decoder: The decoder to read data from.
        public init(from decoder: any Decoder) throws
    }

    /// The source of the zone configuration.
    public let source: HKWorkoutZoneConfiguration.Source

    /// This has moved to `Source`.
    /// Remove once depencies are updated. rdar://173966079 (Remove stale code - HKWorkoutZoneConfiguration.ConfigurationType)
    public enum ConfigurationType : String, Codable, Sendable {

        case automatic

Truncated.

extension

HKWorkoutZoneConfiguration.ConfigurationType

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutZoneConfiguration.ConfigurationType : Equatable
Declaration
extension HKWorkoutZoneConfiguration.ConfigurationType : Equatable {
}
extension

HKWorkoutZoneConfiguration.ConfigurationType

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutZoneConfiguration.ConfigurationType : Hashable
Declaration
extension HKWorkoutZoneConfiguration.ConfigurationType : Hashable {
}
extension

HKWorkoutZoneConfiguration.ConfigurationType

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutZoneConfiguration.ConfigurationType : RawRepresentable
Declaration
extension HKWorkoutZoneConfiguration.ConfigurationType : RawRepresentable {
}
extension

HKWorkoutZoneConfiguration.Source

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutZoneConfiguration.Source : Equatable
Declaration
extension HKWorkoutZoneConfiguration.Source : Equatable {
}
extension

HKWorkoutZoneConfiguration.Source

NewiOSmacOSvisionOSwatchOS
extension HKWorkoutZoneConfiguration.Source : Hashable
Declaration
extension HKWorkoutZoneConfiguration.Source : Hashable {
}
struct

HKWorkoutZoneDuration

NewiOSmacOSvisionOSwatchOS
public struct HKWorkoutZoneDuration : Sendable
Declaration
public struct HKWorkoutZoneDuration : Sendable {

    /// The workout zone.
    public let zone: HKWorkoutZone

    /// The amount of time spent in this zone during the workout or activity, measured in seconds.
    public let duration: TimeInterval
}
struct

HKWorkoutZoneGroup

NewiOSmacOSvisionOSwatchOS
public struct HKWorkoutZoneGroup : Sendable
Declaration
public struct HKWorkoutZoneGroup : Sendable {

    /// The zone configuration that was used for this workout or activity.
    public let configuration: HKWorkoutZoneConfiguration

    /// The time spent in each zone during the workout or activity.
    public let zoneDurations: [HKWorkoutZoneDuration]
}
let

HKCategoryTypeIdentifier.bleedingAfterMenopause

NewiOSmacOSwatchOS
public static let bleedingAfterMenopause: HKCategoryTypeIdentifier
let

HKCategoryTypeIdentifier.menopausalState

NewiOSmacOSwatchOS
public static let menopausalState: HKCategoryTypeIdentifier
func

HKLiveWorkoutBuilderDelegate.workoutBuilder

NewiOSwatchOS
optional func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didUpdateWorkoutZone zoneUpdate: HKLiveWorkoutZoneUpdate)
typealias

HKWorkoutZoneConfiguration.ConfigurationType.RawValue

NewiOSmacOSvisionOSwatchOS
public typealias RawValue = String

The raw type that can be used to represent all values of the conforming type.

Every distinct value of the conforming type has a corresponding unique value of the RawValue type, but there may be values of the RawValue type that don't have a corresponding value of the conforming type.

No APIs match your filter.

← More in Health, Sensors & Motion