Skip to content

Commit

Permalink
Swift 6 language mode support (#25)
Browse files Browse the repository at this point in the history
# Swift 6 language mode support

## ♻️ Current situation & Problem
Repo wasn't maintained properly for the last months, updating for Swift
6 language mode and strict concurrency checking.


## ⚙️ Release Notes 
- Swift 6 language mode support


## 📚 Documentation
--


## ✅ Testing
--


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
philippzagar authored Dec 12, 2024
1 parent a9c4daf commit 79ee967
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
18 changes: 2 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version:6.0

//
// This source file is part of the Stanford Spezi open-source project
Expand All @@ -12,13 +12,6 @@ import class Foundation.ProcessInfo
import PackageDescription


#if swift(<6)
let swiftConcurrency: SwiftSetting = .enableExperimentalFeature("StrictConcurrency")
#else
let swiftConcurrency: SwiftSetting = .enableUpcomingFeature("StrictConcurrency")
#endif


let package = Package(
name: "SpeziHealthKit",
defaultLocalization: "en",
Expand All @@ -29,18 +22,14 @@ let package = Package(
.library(name: "SpeziHealthKit", targets: ["SpeziHealthKit"])
],
dependencies: [
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.7.0")
.package(url: "https://github.com/StanfordSpezi/Spezi", from: "1.8.0")
] + swiftLintPackage(),
targets: [
.target(
name: "SpeziHealthKit",
dependencies: [
.product(name: "Spezi", package: "Spezi")
],
swiftSettings: [
swiftConcurrency,
.enableUpcomingFeature("InferSendableFromCaptures")
],
plugins: [] + swiftLintPlugin()
),
.testTarget(
Expand All @@ -49,9 +38,6 @@ let package = Package(
.product(name: "XCTSpezi", package: "Spezi"),
.target(name: "SpeziHealthKit")
],
swiftSettings: [
swiftConcurrency
],
plugins: [] + swiftLintPlugin()
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ final class HealthKitSampleDataSource: HealthKitDataSource {
}
}

required init( // swiftlint:disable:this function_default_parameter_at_end
required init(
healthStore: HKHealthStore,
standard: any HealthKitConstraint,
sampleType: HKSampleType,
predicate: NSPredicate? = nil,
predicate: NSPredicate? = nil, // swiftlint:disable:this function_default_parameter_at_end
deliverySetting: HealthKitDeliverySetting
) {
self.healthStore = healthStore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ extension HKHealthStore {
// "Whenever a matching sample is added to or deleted from the HealthKit store,
// the system calls the query’s update handler on the same background queue (but not necessarily the same thread)."
// So, the observerQuery has to be @Sendable!


// Sadly necessary to enable capture of the `completionHandler` within the `Task`s below (isolation error)
nonisolated(unsafe) let completionHandler = completionHandler

guard error == nil,
let samples else {
Logger.healthKit.error("Failed HealthKit background delivery for observer query \(query) with error: \(error)")
Expand Down
2 changes: 1 addition & 1 deletion Sources/SpeziHealthKit/HealthKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public final class HealthKit: Module, EnvironmentAccessible, DefaultInitializabl
public func triggerDataSourceCollection() async {
await withTaskGroup(of: Void.self) { group in
for healthKitComponent in healthKitComponents {
group.addTask { @MainActor in
group.addTask { @MainActor @Sendable in
await healthKitComponent.triggerManualDataSourceCollection()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SpeziHealthKit/Logging/Logger+HealthKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// SPDX-License-Identifier: MIT
//


import OSLog


extension Logger {
/// Logs the view cycles like a view that appeared.
static let healthKit = Logger(subsystem: "edu.stanford.spezi", category: "HealthKit")
Expand Down

0 comments on commit 79ee967

Please sign in to comment.