-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Notification realted infrastructure again. Moving to SpeziNoti…
…fications
- Loading branch information
Showing
18 changed files
with
110 additions
and
394 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ builder: | |
configs: | ||
- platform: ios | ||
scheme: Spezi | ||
swift_version: 6 | ||
documentation_targets: | ||
- Spezi | ||
- XCTSpezi |
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
Sources/Spezi/Capabilities/ApplicationPropertyWrapper.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Access a property or action of the Spezi application. | ||
@propertyWrapper | ||
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 let keyPath: KeyPath<Spezi, Value> | ||
private let state = State() | ||
|
||
|
||
/// Access the application property. | ||
public var wrappedValue: Value { | ||
if let shadowCopy = state.shadowCopy { | ||
return shadowCopy | ||
} | ||
|
||
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] | ||
} | ||
|
||
/// Initialize a new `@Application` property wrapper | ||
/// - Parameter keyPath: The property to access. | ||
public init(_ keyPath: KeyPath<Spezi, Value>) { | ||
self.keyPath = keyPath | ||
} | ||
} | ||
|
||
|
||
extension _ApplicationPropertyWrapper: SpeziPropertyWrapper { | ||
func inject(spezi: Spezi) { | ||
state.spezi = spezi | ||
if spezi.createsCopy(keyPath) { | ||
state.shadowCopy = spezi[keyPath: keyPath] | ||
} | ||
} | ||
|
||
func clear() { | ||
state.spezi = nil | ||
state.shadowCopy = nil | ||
} | ||
} | ||
|
||
|
||
extension Module { | ||
/// Access a property or action of the application. | ||
/// | ||
/// The `@Application` property wrapper can be used inside your `Module` to | ||
/// access a property or action of your application. | ||
/// | ||
/// - Note: You can access the contents of `@Application` once your ``Module/configure()-5pa83`` method is called | ||
/// (e.g., it must not be used in the `init`). | ||
/// | ||
/// Below is a short code example: | ||
/// | ||
/// ```swift | ||
/// class ExampleModule: Module { | ||
/// @Application(\.logger) | ||
/// var logger | ||
/// | ||
/// func configure() { | ||
/// logger.info("Module is being configured ...") | ||
/// } | ||
/// } | ||
/// ``` | ||
public typealias Application<Value> = _ApplicationPropertyWrapper<Value> | ||
} |
Oops, something went wrong.