Documentation Archive Developer
Search

HealthKit Changes for Objective-C

HealthKit

HKAnchoredObjectQuery.h

DeclarationDeprecation
From
- (instancetype)initWithType:(HKSampleType *)type predicate:(NSPredicate *)predicate anchor:(NSUInteger)anchor limit:(NSUInteger)limit completionHandler:(void (^)(HKAnchoredObjectQuery *query, NSArray *results, NSUInteger newAnchor, NSError *error))handler
--
To
- (instancetype _Nonnull)initWithType:(HKSampleType * _Nonnull)type predicate:(NSPredicate * _Nullable)predicate anchor:(NSUInteger)anchor limit:(NSUInteger)limit completionHandler:(void (^ _Nonnull)(HKAnchoredObjectQuery * _Nonnull query, NSArray<__kindof HKSample *> * _Nullable results, NSUInteger newAnchor, NSError * _Nullable error))handler
iOS 9.0

HKCategorySample.h

Declaration
From
+ (instancetype)categorySampleWithType:(HKCategoryType *)type value:(NSInteger)value startDate:(NSDate *)startDate endDate:(NSDate *)endDate metadata:(NSDictionary *)metadata
To
+ (instancetype _Nonnull)categorySampleWithType:(HKCategoryType * _Nonnull)type value:(NSInteger)value startDate:(NSDate * _Nonnull)startDate endDate:(NSDate * _Nonnull)endDate metadata:(NSDictionary<NSString *,id> * _Nullable)metadata

HKCorrelation.h

Modified HKCorrelation
Protocols
FromNSSecureCoding
To--

Declaration
From
+ (instancetype)correlationWithType:(HKCorrelationType *)correlationType startDate:(NSDate *)startDate endDate:(NSDate *)endDate objects:(NSSet *)objects
To
+ (instancetype _Nonnull)correlationWithType:(HKCorrelationType * _Nonnull)correlationType startDate:(NSDate * _Nonnull)startDate endDate:(NSDate * _Nonnull)endDate objects:(NSSet<HKSample *> * _Nonnull)objects

Declaration
From
+ (instancetype)correlationWithType:(HKCorrelationType *)correlationType startDate:(NSDate *)startDate endDate:(NSDate *)endDate objects:(NSSet *)objects metadata:(NSDictionary *)metadata
To
+ (instancetype _Nonnull)correlationWithType:(HKCorrelationType * _Nonnull)correlationType startDate:(NSDate * _Nonnull)startDate endDate:(NSDate * _Nonnull)endDate objects:(NSSet<HKSample *> * _Nonnull)objects metadata:(NSDictionary<NSString *,id> * _Nullable)metadata

Declaration
From
@property(readonly, copy) NSSet *objects
To
@property(readonly, copy, nonnull) NSSet<__kindof HKSample *> *objects

Declaration
From
- (NSSet *)objectsForType:(HKObjectType *)objectType
To
- (NSSet<__kindof HKSample *> * _Nonnull)objectsForType:(HKObjectType * _Nonnull)objectType

HKCorrelationQuery.h

Declaration
From
- (instancetype)initWithType:(HKCorrelationType *)correlationType predicate:(NSPredicate *)predicate samplePredicates:(NSDictionary *)samplePredicates completion:(void (^)(HKCorrelationQuery *query, NSArray *correlations, NSError *error))completion
To
- (instancetype _Nonnull)initWithType:(HKCorrelationType * _Nonnull)correlationType predicate:(NSPredicate * _Nullable)predicate samplePredicates:(NSDictionary<HKSampleType *,NSPredicate *> * _Nullable)samplePredicates completion:(void (^ _Nonnull)(HKCorrelationQuery * _Nonnull query, NSArray<HKCorrelation *> * _Nullable correlations, NSError * _Nullable error))completion

Declaration
From
@property(readonly, copy) NSDictionary *samplePredicates
To
@property(readonly, copy, nullable) NSDictionary<__kindof HKSampleType *,NSPredicate *> *samplePredicates

HKDefines.h

HKDeletedObject.h (Added)

HKDevice.h (Added)

HKHealthStore.h

Protocols
From--
ToNSCopying, NSSecureCoding

Protocols
From--
ToNSCopying, NSSecureCoding

Modified HKHealthStore
App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

Declaration
From
- (void)addSamples:(NSArray *)samples toWorkout:(HKWorkout *)workout completion:(void (^)(BOOL success, NSError *error))completion
To
- (void)addSamples:(NSArray<HKSample *> * _Nonnull)samples toWorkout:(HKWorkout * _Nonnull)workout completion:(void (^ _Nonnull)(BOOL success, NSError * _Nullable error))completion

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

Declaration
From
- (void)preferredUnitsForQuantityTypes:(NSSet *)quantityTypes completion:(void (^)(NSDictionary *preferredUnits, NSError *error))completion
To
- (void)preferredUnitsForQuantityTypes:(NSSet<HKQuantityType *> * _Nonnull)quantityTypes completion:(void (^ _Nonnull)(NSDictionary<HKQuantityType *,HKUnit *> * _Nonnull preferredUnits, NSError * _Nullable error))completion

DeclarationApp Extension[Available]App Extension[Message]
From
- (void)requestAuthorizationToShareTypes:(NSSet *)typesToShare readTypes:(NSSet *)typesToRead completion:(void (^)(BOOL success, NSError *error))completion
noHealthKit is not supported in extensions
To
- (void)requestAuthorizationToShareTypes:(NSSet<HKSampleType *> * _Nullable)typesToShare readTypes:(NSSet<HKObjectType *> * _Nullable)typesToRead completion:(void (^ _Nonnull)(BOOL success, NSError * _Nullable error))completion
----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

DeclarationApp Extension[Available]App Extension[Message]
From
- (void)saveObjects:(NSArray *)objects withCompletion:(void (^)(BOOL success, NSError *error))completion
noHealthKit is not supported in extensions
To
- (void)saveObjects:(NSArray<HKObject *> * _Nonnull)objects withCompletion:(void (^ _Nonnull)(BOOL success, NSError * _Nullable error))completion
----

App Extension[Available]App Extension[Message]
FromnoHealthKit is not supported in extensions
To----

HKMetadata.h

HKObject.h

Declaration
From
@property(readonly, copy) NSDictionary *metadata
To
@property(readonly, copy, nullable) NSDictionary<NSString *,id> *metadata

Deprecation
From--
ToiOS 9.0

HKQuantitySample.h

Declaration
From
+ (instancetype)quantitySampleWithType:(HKQuantityType *)quantityType quantity:(HKQuantity *)quantity startDate:(NSDate *)startDate endDate:(NSDate *)endDate metadata:(NSDictionary *)metadata
To
+ (instancetype _Nonnull)quantitySampleWithType:(HKQuantityType * _Nonnull)quantityType quantity:(HKQuantity * _Nonnull)quantity startDate:(NSDate * _Nonnull)startDate endDate:(NSDate * _Nonnull)endDate metadata:(NSDictionary<NSString *,id> * _Nullable)metadata

HKQuery.h

Declaration
From
+ (NSPredicate *)predicateForObjectsFromSources:(NSSet *)sources
To
+ (NSPredicate * _Nonnull)predicateForObjectsFromSources:(NSSet<HKSource *> * _Nonnull)sources

Declaration
From
+ (NSPredicate *)predicateForObjectsWithUUIDs:(NSSet *)UUIDs
To
+ (NSPredicate * _Nonnull)predicateForObjectsWithUUIDs:(NSSet<NSUUID *> * _Nonnull)UUIDs

HKSampleQuery.h

Declaration
From
- (instancetype)initWithSampleType:(HKSampleType *)sampleType predicate:(NSPredicate *)predicate limit:(NSUInteger)limit sortDescriptors:(NSArray *)sortDescriptors resultsHandler:(void (^)(HKSampleQuery *query, NSArray *results, NSError *error))resultsHandler
To
- (instancetype _Nonnull)initWithSampleType:(HKSampleType * _Nonnull)sampleType predicate:(NSPredicate * _Nullable)predicate limit:(NSUInteger)limit sortDescriptors:(NSArray<NSSortDescriptor *> * _Nullable)sortDescriptors resultsHandler:(void (^ _Nonnull)(HKSampleQuery * _Nonnull query, NSArray<__kindof HKSample *> * _Nullable results, NSError * _Nullable error))resultsHandler

Declaration
From
@property(readonly, copy) NSArray *sortDescriptors
To
@property(readonly, copy, nullable) NSArray<NSSortDescriptor *> *sortDescriptors

HKSourceQuery.h

Declaration
From
- (instancetype)initWithSampleType:(HKSampleType *)sampleType samplePredicate:(NSPredicate *)objectPredicate completionHandler:(void (^)(HKSourceQuery *query, NSSet *sources, NSError *error))completionHandler
To
- (instancetype _Nonnull)initWithSampleType:(HKSampleType * _Nonnull)sampleType samplePredicate:(NSPredicate * _Nullable)objectPredicate completionHandler:(void (^ _Nonnull)(HKSourceQuery * _Nonnull query, NSSet<HKSource *> * _Nullable sources, NSError * _Nullable error))completionHandler

HKSourceRevision.h (Added)

HKStatistics.h

Declaration
From
@property(readonly, strong) NSArray *sources
To
@property(readonly, strong, nullable) NSArray<HKSource *> *sources

HKStatisticsCollectionQuery.h

Declaration
From
- (NSSet *)sources
To
- (NSSet<HKSource *> * _Nonnull)sources

Declaration
From
- (NSArray *)statistics
To
- (NSArray<HKStatistics *> * _Nonnull)statistics

HKTypeIdentifiers.h

HKUnit.h

HKWorkout.h

Declaration
From
@property(readonly, copy) NSArray *workoutEvents
To
@property(readonly, copy, nullable) NSArray<HKWorkoutEvent *> *workoutEvents

Declaration
From
+ (instancetype)workoutWithActivityType:(HKWorkoutActivityType)workoutActivityType startDate:(NSDate *)startDate endDate:(NSDate *)endDate duration:(NSTimeInterval)duration totalEnergyBurned:(HKQuantity *)totalEnergyBurned totalDistance:(HKQuantity *)totalDistance metadata:(NSDictionary *)metadata
To
+ (instancetype _Nonnull)workoutWithActivityType:(HKWorkoutActivityType)workoutActivityType startDate:(NSDate * _Nonnull)startDate endDate:(NSDate * _Nonnull)endDate duration:(NSTimeInterval)duration totalEnergyBurned:(HKQuantity * _Nullable)totalEnergyBurned totalDistance:(HKQuantity * _Nullable)totalDistance metadata:(NSDictionary<NSString *,id> * _Nullable)metadata

Declaration
From
+ (instancetype)workoutWithActivityType:(HKWorkoutActivityType)workoutActivityType startDate:(NSDate *)startDate endDate:(NSDate *)endDate workoutEvents:(NSArray *)workoutEvents totalEnergyBurned:(HKQuantity *)totalEnergyBurned totalDistance:(HKQuantity *)totalDistance metadata:(NSDictionary *)metadata
To
+ (instancetype _Nonnull)workoutWithActivityType:(HKWorkoutActivityType)workoutActivityType startDate:(NSDate * _Nonnull)startDate endDate:(NSDate * _Nonnull)endDate workoutEvents:(NSArray<HKWorkoutEvent *> * _Nullable)workoutEvents totalEnergyBurned:(HKQuantity * _Nullable)totalEnergyBurned totalDistance:(HKQuantity * _Nullable)totalDistance metadata:(NSDictionary<NSString *,id> * _Nullable)metadata

HKWorkoutSession.h (Added)