-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce EnvironmentAccessible and allow for later intialization of @…
- Loading branch information
Showing
7 changed files
with
88 additions
and
15 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Sources/Spezi/Capabilities/Observable/EnvironmentAccessible.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,38 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SwiftUI | ||
|
||
|
||
/// Places a ``Module`` into the SwiftUI environment. | ||
/// | ||
/// Below is a short code example how you would declare an environment accessible module, | ||
/// and how to access it within SwiftUI, if it is configured in your ``Configuration``. | ||
/// | ||
/// ```swift | ||
/// public class ExampleModule: Module, EnvironmentAccessible { | ||
/// // ... implement your functionality | ||
/// } | ||
/// | ||
/// | ||
/// struct ExampleView: View { | ||
/// @Environment(ExampleModule.self) var module | ||
/// | ||
/// var body: some View { | ||
/// // ... access module functionality | ||
/// } | ||
/// } | ||
/// ``` | ||
public protocol EnvironmentAccessible: AnyObject, Observable {} | ||
|
||
|
||
extension EnvironmentAccessible { | ||
var viewModifier: any ViewModifier { | ||
ModelModifier(model: self) | ||
} | ||
} |
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
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
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
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
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
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