generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Add ConfigureTipKit Module ## ♻️ Current situation & Problem This PR adds the `ConfigureTipKit` module to easily configure TipKit (or require TipKit to be configured) across the Spezi framework ecosystem. ## ⚙️ Release Notes * Add new `ConfigureTipKit` module. ## 📚 Documentation Documentation catalog was adjusted. ## ✅ Testing Basic testing was added that calls the new code paths. ## 📝 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
Showing
13 changed files
with
220 additions
and
7 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
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,57 @@ | ||
// | ||
// 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 Spezi | ||
@_spi(TestingSupport) import SpeziFoundation | ||
import TipKit | ||
|
||
|
||
/// Configure TipKit. | ||
/// | ||
/// This module allows to easily and globally configure [TipKit](https://developer.apple.com/documentation/TipKit) by calling | ||
/// [`Tips/configure(_:)`](https://developer.apple.com/documentation/tipkit/tips/configure(_:)). | ||
/// You can use the Spezi Dependency system to require TipKit to be configured or can use the `@Environment` property wrapper in your | ||
/// SwiftUI views to verify that TipKit was configured when using TipKit-based View components. | ||
/// | ||
/// - Note: The Module will automatically [`showAllTipsForTesting()`](https://developer.apple.com/documentation/tipkit/tips/showalltipsfortesting()) | ||
/// if either the Module is initialized within a SwiftUI preview or the `testingTips` <doc:SPI#RuntimeConfig> is supplied via the command line. | ||
public class ConfigureTipKit: Module, DefaultInitializable, EnvironmentAccessible { | ||
private let configuration: [Tips.ConfigurationOption] | ||
|
||
@Application(\.logger) private var logger | ||
|
||
|
||
/// Configure TipKit. | ||
/// - Parameter configuration: TipKit configuration options. | ||
public init(_ configuration: [Tips.ConfigurationOption]) { | ||
self.configuration = configuration | ||
} | ||
|
||
/// Configure TipKit with default options. | ||
public required convenience init() { | ||
self.init([]) | ||
} | ||
|
||
public func configure() { | ||
if RuntimeConfig.testingTips || ProcessInfo.processInfo.isPreviewSimulator { | ||
Tips.showAllTipsForTesting() | ||
} | ||
do { | ||
try Tips.configure(configuration) | ||
} catch { | ||
logger.error("Failed to configure TipKit: \(error)") | ||
} | ||
} | ||
} | ||
|
||
|
||
extension RuntimeConfig { | ||
/// Enable testing tips | ||
@_spi(TestingSupport) | ||
public static let testingTips = CommandLine.arguments.contains("--testTips") | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,9 @@ | |
} | ||
} | ||
} | ||
}, | ||
"Dismiss" : { | ||
|
||
}, | ||
"Error" : { | ||
"comment" : "View State default error title", | ||
|
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,41 @@ | ||
# System Programming Interfaces | ||
|
||
<!-- | ||
# | ||
# 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 | ||
# | ||
--> | ||
|
||
An overview of System Programming Interfaces (SPIs) provided by SpeziViews. | ||
|
||
## Overview | ||
|
||
A [System Programming Interface](https://blog.eidinger.info/system-programming-interfaces-spi-in-swift-explained) is a subset of API | ||
that is targeted only for certain users (e.g., framework developers) and might not be necessary or useful for app development. | ||
Therefore, these interfaces are not visible by default and need to be explicitly imported. | ||
This article provides an overview of supported SPI provided by SpeziFoundation | ||
|
||
### TestingSupport | ||
|
||
The `TestingSupport` SPI provides additional interfaces that are useful for unit and UI testing. | ||
Annotate your import statement as follows. | ||
|
||
```swift | ||
@_spi(TestingSupport) import SpeziViews | ||
``` | ||
|
||
#### RuntimeConfig | ||
|
||
[`RuntimeConfig`](https://swiftpackageindex.com/stanfordspezi/spezifoundation/documentation/spezifoundation/spi#RuntimeConfig) is provided by | ||
[SpeziFoundation](https://swiftpackageindex.com/stanfordspezi/spezifoundation/documentation/spezifoundation) for a central place to | ||
provide runtime configurations. | ||
|
||
SpeziViews adds the following extensions: | ||
|
||
- `RuntimeConfig/testingTips`: Holds `true` if the `--testTips` command line flag was supplied to indicate to always show Tips when using | ||
``ConfigureTipKit``. | ||
|
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
Oops, something went wrong.