Skip to content

Commit

Permalink
Fix healthKit
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 10, 2024
1 parent 75c514a commit 5fcea82
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import Foundation
import OversizeCore
import OversizeModels

#if !os(tvOS)
#if canImport(HealthKit)
@available(iOS 15, macOS 13.0, *)
public class BloodPressureService: HealthKitService {
public class BloodPressureService: HealthKitService, @unchecked Sendable {
private let bloodPressureType = HKQuantityType.correlationType(forIdentifier: HKCorrelationTypeIdentifier.bloodPressure)
private let bloodPressureSystolicType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureSystolic)
private let bloodPressureDiastolicType = HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bloodPressureDiastolic)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import OversizeCore
import OversizeModels

#if !os(tvOS)
#if canImport(HealthKit)
@available(iOS 15, macOS 13.0, *)
open class HealthKitService: @unchecked Sendable {
var healthStore: HKHealthStore?
Expand All @@ -28,29 +28,23 @@ import OversizeModels
guard let healthStore else {
return .failure(AppError.healthKit(type: .savingItem))
}
return await withCheckedContinuation { continuation in
healthStore.save(quantitySample) { _, error in
if error != nil {
continuation.resume(returning: .failure(AppError.healthKit(type: .savingItem)))
} else {
continuation.resume(returning: .success(quantitySample))
}
}
do {
try await healthStore.save(quantitySample)
return .success(quantitySample)
} catch {
return .failure(AppError.healthKit(type: .savingItem))
}
}

func saveCorrelation(_ correlation: HKCorrelation) async -> Result<HKCorrelation, AppError> {
guard let healthStore else {
return .failure(AppError.healthKit(type: .savingItem))
}
return await withCheckedContinuation { continuation in
healthStore.save(correlation) { _, error in
if error != nil {
continuation.resume(returning: .failure(AppError.healthKit(type: .savingItem)))
} else {
continuation.resume(returning: .success(correlation))
}
}
do {
try await healthStore.save(correlation)
return .success(correlation)
} catch {
return .failure(AppError.healthKit(type: .savingItem))
}
}

Expand Down Expand Up @@ -161,26 +155,27 @@ import OversizeModels
}

func deleteObject(_ object: HKObject) async -> Result<HKObject, AppError> {
await withCheckedContinuation { continuation in
self.healthStore?.delete(object, withCompletion: { _, error in
if error != nil {
continuation.resume(returning: .failure(AppError.healthKit(type: .deleteItem)))
} else {
continuation.resume(returning: .success(object))
}
})
guard let healthStore else {
return .failure(AppError.healthKit(type: .deleteItem))
}
do {
try await healthStore.delete(object)
return .success(object)
} catch {
return .failure(AppError.healthKit(type: .deleteItem))
}
}


func deleteObjects(_ objects: [HKObject]) async -> Result<[HKObject], AppError> {
await withCheckedContinuation { continuation in
self.healthStore?.delete(objects, withCompletion: { _, error in
if error != nil {
continuation.resume(returning: .failure(AppError.healthKit(type: .deleteItem)))
} else {
continuation.resume(returning: .success(objects))
}
})
guard let healthStore else {
return .failure(AppError.healthKit(type: .deleteItem))
}
do {
try await healthStore.delete(objects)
return .success(objects)
} catch {
return .failure(AppError.healthKit(type: .deleteItem))
}
}
}
Expand Down
File renamed without changes.

0 comments on commit 5fcea82

Please sign in to comment.