Skip to content

Commit

Permalink
Migrate to @_spi instead of @testable (#101)
Browse files Browse the repository at this point in the history
# Migrate to @_spi instead of @testable

## ♻️ Current situation & Problem
Currently, we use `@testable` within `XCTSpezi` to access the internal
interface of `Spezi`. This introduces complications for people using
`XCTSpezi`. Using @_spi is also better as we have a reduced interface
that we expose and even allow for others to leverage the same power when
accessing the System Programming Interface.


## ⚙️ Release Notes 
* Fixed an issue where compilation fails in certain test environments.


## 📚 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 Mar 8, 2024
1 parent 0ced3ef commit ce8b29f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
6 changes: 4 additions & 2 deletions Sources/Spezi/Module/ModuleCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
///
/// You can not create a ``ModuleCollection`` yourself. Please use the ``ModuleBuilder`` to create a ``ModuleCollection``.
public class ModuleCollection {
let elements: [any Module]

/// The elements of the collection.
@_spi(Spezi)
public let elements: [any Module]


init(elements: [any Module]) {
self.elements = elements
Expand Down
14 changes: 7 additions & 7 deletions Sources/Spezi/Spezi/KnowledgeSources/LaunchOptionsKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
import SpeziFoundation
import SwiftUI


struct LaunchOptionsKey: DefaultProvidingKnowledgeSource {
typealias Anchor = SpeziAnchor
@_spi(Spezi)
public struct LaunchOptionsKey: DefaultProvidingKnowledgeSource {
public typealias Anchor = SpeziAnchor

#if os(iOS) || os(visionOS) || os(tvOS)
typealias Value = [UIApplication.LaunchOptionsKey: Any]
public typealias Value = [UIApplication.LaunchOptionsKey: Any]
#elseif os(macOS)
/// Currently not supported as ``SpeziAppDelegate/applicationWillFinishLaunching(_:)`` on macOS
/// is executed after the initialization of ``Spezi`` via `View/spezi(_:)` is done, breaking our initialization assumption in ``SpeziAppDelegate/applicationWillFinishLaunching(_:)``.
typealias Value = [Never: Any]
public typealias Value = [Never: Any]
#else // os(watchOS)
typealias Value = [Never: Any]
public typealias Value = [Never: Any]
#endif

static let defaultValue: Value = [:]
public static let defaultValue: Value = [:]
}


Expand Down
13 changes: 11 additions & 2 deletions Sources/Spezi/Spezi/Spezi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public class Spezi {
)


var lifecycleHandler: [LifecycleHandler] {
@_spi(Spezi)
public var lifecycleHandler: [LifecycleHandler] {
storage.collect(allOf: LifecycleHandler.self)
}

Expand All @@ -108,7 +109,15 @@ public class Spezi {
self.init(standard: configuration.standard, modules: configuration.modules.elements, storage: storage)
}

init(

/// Create a new Spezi instance.
///
/// - Parameters:
/// - standard: The standard to use.
/// - modules: The collection of modules to initialize.
/// - storage: Optional, initial storage to inject.
@_spi(Spezi)
public init(
standard: any Standard,
modules: [any Module],
storage: consuming SpeziStorage = SpeziStorage()
Expand Down
5 changes: 4 additions & 1 deletion Sources/Spezi/Standard/DefaultStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
//


actor DefaultStandard: Standard {}
@_spi(Spezi)
public actor DefaultStandard: Standard {
public init() {}
}
4 changes: 2 additions & 2 deletions Sources/XCTSpezi/DependencyResolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// SPDX-License-Identifier: MIT
//

@testable import Spezi
@_implementationOnly import SwiftUI
@_spi(Spezi) import Spezi
import SwiftUI


/// Configure and resolve the dependency tree for a collection of [`Module`](https://swiftpackageindex.com/stanfordspezi/spezi/documentation/spezi/module)s.
Expand Down
2 changes: 1 addition & 1 deletion Tests/SpeziTests/ModuleTests/ModuleBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// SPDX-License-Identifier: MIT
//

@testable import Spezi
@testable @_spi(Spezi) import Spezi
import XCTest
import XCTRuntimeAssertions

Expand Down

0 comments on commit ce8b29f

Please sign in to comment.