-
-
Save marcgeld/f76d61b495a070e23384 to your computer and use it in GitHub Desktop.
HealthKit examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let healthStore = HKHealthStore() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let type = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierBodyMass) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.healthStore.executeQuery(HKSampleQuery( | |
sampleType: type, | |
predicate: HKQuery.predicateForSamplesWithStartDate( | |
NSDate.distantPast() as NSDate, | |
endDate: NSDate.distantFuture() as NSDate, | |
options: .None | |
), | |
limit: 0, | |
sortDescriptors: nil, | |
resultsHandler: { (query: HKSampleQuery!, results: [AnyObject]!, err: NSError?) -> Void in | |
if err != nil { | |
println(err) | |
return | |
} | |
for result in results as [HKQuantitySample]! { | |
println(result) | |
} | |
} | |
)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let now = NSDate() | |
self.healthStore.saveObject( | |
HKQuantitySample( | |
type: type, | |
quantity: HKQuantity(unit: HKUnit(fromString: "lb"), doubleValue: 100), | |
startDate: now, | |
endDate: now, | |
metadata: [HKMetadataKeyWasUserEntered: true] | |
), | |
withCompletion: nil | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment