Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-beta.1"),
.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
Loading