I am trying to determine what kind of HKQuantityTypeIdentifier matches the measurements provided in a particular Health Kit sample To determine this, I have tried the following:
if(hkSample.quantityType == HKQuantityTypeIdentifierDistanceCycling) ...
if([hkSample.quantityType isEqual: HKQuantityTypeIdentifierDistanceCycling]) ...
and
if([hkSample.quantityType isEqualToString: HKQuantityTypeIdentifierDistanceCycling]) ...
The first two options run but give a negative result even when the types should be matching and the last option gives a run-time NSException error for an unknown method. What's the proper way to determine which type maths an HKQuantitySample type?
quantityType
is an HKQuantityType, not a string, so it doesn't respond to -isEqualToString:
. You need to compare it with another HKQuantityType via -isEqual:
, like this:
if ([hkSample.quantityType isEqual:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceCycling]])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.