Skip to content

Commit

Permalink
Provide integration points for SpeziNotifications, Swift 6 and silenc…
Browse files Browse the repository at this point in the history
…e some warnings (#117)

# Provide integration points for SpeziNotifications, Swift 6 and silence
some warnings

## ♻️ Current situation & Problem
SpeziNotifications
(StanfordSpezi/SpeziNotifications#1) is a new
framework in the Spezi ecosystem that helps dealing with
UserNotifications in your application. Some elements that are currently
defined in Spezi are going to move to SpeziNotifications. We will fully
move all of this infrastructure in a future breaking release of Spezi.
For now, we make sure to have some of the required infrastructure
accessible by SpeziNetworking.

The `SpeziNotificationCenterDelegate` and associated protocols will stay
for now but can eventually be fully moved to SpeziNotifications. For
now, SpeziNotifications will re-export all relevant types so it is
easier for users to be prepared for the change.
## ⚙️ Release Notes 
* Deprecated the remote notifications actions declared on Spezi.
SpeziNotifications declares the exact same actions.
* Allow SpeziNotifications to receive the delegate calls that are made
after calling `registerForRemoteNotifications`.
* Move the Package to the Swift 6 toolchain.
* Silence some deprecation warnings through some visibility tricks.


## 📚 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
Supereg authored Oct 28, 2024
1 parent d5c8eec commit 4513a69
Show file tree
Hide file tree
Showing 42 changed files with 652 additions and 522 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ jobs:
scheme: Spezi-Package
resultBundle: Spezi-Package-iOS.xcresult
artifactname: Spezi-Package-iOS.xcresult
buildandtest_ios_latest:
name: Build and Test Swift Package iOS Latest
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted"]'
scheme: Spezi-Package
xcodeversion: latest
swiftVersion: 6
resultBundle: Spezi-Package-iOS-Latest.xcresult
artifactname: Spezi-Package-iOS-Latest.xcresult
buildandtest_watchos:
name: Build and Test Swift Package watchOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
Expand Down Expand Up @@ -79,17 +69,6 @@ jobs:
scheme: TestApp
resultBundle: TestApp-iOS.xcresult
artifactname: TestApp-iOS.xcresult
buildandtestuitests_ios_latest:
name: Build and Test UI Tests iOS Latest
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
with:
runsonlabels: '["macOS", "self-hosted"]'
path: Tests/UITests
scheme: TestApp
xcodeversion: latest
swiftVersion: 6
resultBundle: TestApp-iOS-Latest.xcresult
artifactname: TestApp-iOS-Latest.xcresult
buildandtestuitests_visionos:
name: Build and Test UI Tests visionOS
uses: StanfordSpezi/.github/.github/workflows/xcodebuild-or-fastlane.yml@v2
Expand Down
1 change: 1 addition & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ builder:
configs:
- platform: ios
scheme: Spezi
swift_version: 6
documentation_targets:
- Spezi
- XCTSpezi
21 changes: 3 additions & 18 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 @@ -11,12 +11,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: "Spezi",
Expand All @@ -33,8 +27,8 @@ let package = Package(
.library(name: "XCTSpezi", targets: ["XCTSpezi"])
],
dependencies: [
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation", from: "2.0.0-beta.1"),
.package(url: "https://github.com/StanfordBDHG/XCTRuntimeAssertions", from: "1.1.1"),
.package(url: "https://github.com/StanfordSpezi/SpeziFoundation.git", from: "2.0.0"),
.package(url: "https://github.com/StanfordBDHG/XCTRuntimeAssertions.git", from: "1.1.1"),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.1")
] + swiftLintPackage(),
targets: [
Expand All @@ -45,19 +39,13 @@ let package = Package(
.product(name: "XCTRuntimeAssertions", package: "XCTRuntimeAssertions"),
.product(name: "OrderedCollections", package: "swift-collections")
],
swiftSettings: [
swiftConcurrency
],
plugins: [] + swiftLintPlugin()
),
.target(
name: "XCTSpezi",
dependencies: [
.target(name: "Spezi")
],
swiftSettings: [
swiftConcurrency
],
plugins: [] + swiftLintPlugin()
),
.testTarget(
Expand All @@ -67,9 +55,6 @@ let package = Package(
.target(name: "XCTSpezi"),
.product(name: "XCTRuntimeAssertions", package: "XCTRuntimeAssertions")
],
swiftSettings: [
swiftConcurrency
],
plugins: [] + swiftLintPlugin()
)
]
Expand Down
29 changes: 17 additions & 12 deletions Sources/Spezi/Capabilities/ApplicationPropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,29 @@
// SPDX-License-Identifier: MIT
//

import SwiftUI

/// Refer to the documentation of ``Module/Application``.

/// Access a property or action of the Spezi application.
@propertyWrapper
public class _ApplicationPropertyWrapper<Value> { // swiftlint:disable:this type_name
private let keyPath: KeyPath<Spezi, Value>
public struct _ApplicationPropertyWrapper<Value> { // swiftlint:disable:this type_name
private final class State {
weak var spezi: Spezi?
/// Some KeyPaths are declared to copy the value upon injection and not query them every time.
var shadowCopy: Value?
}

private weak var spezi: Spezi?
/// Some KeyPaths are declared to copy the value upon injection and not query them every time.
private var shadowCopy: Value?
private let keyPath: KeyPath<Spezi, Value>
private let state = State()


/// Access the application property.
public var wrappedValue: Value {
if let shadowCopy {
if let shadowCopy = state.shadowCopy {
return shadowCopy
}

guard let spezi else {
guard let spezi = state.spezi else {
preconditionFailure("Underlying Spezi instance was not yet injected. @Application cannot be accessed within the initializer!")
}
return spezi[keyPath: keyPath]
Expand All @@ -39,15 +44,15 @@ public class _ApplicationPropertyWrapper<Value> { // swiftlint:disable:this type

extension _ApplicationPropertyWrapper: SpeziPropertyWrapper {
func inject(spezi: Spezi) {
self.spezi = spezi
state.spezi = spezi
if spezi.createsCopy(keyPath) {
self.shadowCopy = spezi[keyPath: keyPath]
state.shadowCopy = spezi[keyPath: keyPath]
}
}

func clear() {
spezi = nil
shadowCopy = nil
state.spezi = nil
state.shadowCopy = nil
}
}

Expand Down
Loading

0 comments on commit 4513a69

Please sign in to comment.