From 48410c656eaf96f3b29cbe8008e2ace88ce091d8 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Thu, 7 Mar 2024 19:31:31 -0800 Subject: [PATCH 1/3] Migrate to @_spi instead of @testable --- Sources/Spezi/Module/ModuleCollection.swift | 5 +++-- .../Spezi/KnowledgeSources/LaunchOptionsKey.swift | 14 +++++++------- Sources/Spezi/Spezi/Spezi.swift | 6 ++++-- Sources/Spezi/Standard/DefaultStandard.swift | 5 ++++- Sources/XCTSpezi/DependencyResolution.swift | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Sources/Spezi/Module/ModuleCollection.swift b/Sources/Spezi/Module/ModuleCollection.swift index 79b2ba26..723c4a12 100644 --- a/Sources/Spezi/Module/ModuleCollection.swift +++ b/Sources/Spezi/Module/ModuleCollection.swift @@ -11,8 +11,9 @@ /// /// You can not create a ``ModuleCollection`` yourself. Please use the ``ModuleBuilder`` to create a ``ModuleCollection``. public class ModuleCollection { - let elements: [any Module] - + @_spi(Spezi) + public let elements: [any Module] + init(elements: [any Module]) { self.elements = elements diff --git a/Sources/Spezi/Spezi/KnowledgeSources/LaunchOptionsKey.swift b/Sources/Spezi/Spezi/KnowledgeSources/LaunchOptionsKey.swift index bd823142..b1db01f1 100644 --- a/Sources/Spezi/Spezi/KnowledgeSources/LaunchOptionsKey.swift +++ b/Sources/Spezi/Spezi/KnowledgeSources/LaunchOptionsKey.swift @@ -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 = [:] } diff --git a/Sources/Spezi/Spezi/Spezi.swift b/Sources/Spezi/Spezi/Spezi.swift index cd17ee1a..a4c98115 100644 --- a/Sources/Spezi/Spezi/Spezi.swift +++ b/Sources/Spezi/Spezi/Spezi.swift @@ -91,7 +91,8 @@ public class Spezi { ) - var lifecycleHandler: [LifecycleHandler] { + @_spi(Spezi) + public var lifecycleHandler: [LifecycleHandler] { storage.collect(allOf: LifecycleHandler.self) } @@ -108,7 +109,8 @@ public class Spezi { self.init(standard: configuration.standard, modules: configuration.modules.elements, storage: storage) } - init( + @_spi(Spezi) + public init( standard: any Standard, modules: [any Module], storage: consuming SpeziStorage = SpeziStorage() diff --git a/Sources/Spezi/Standard/DefaultStandard.swift b/Sources/Spezi/Standard/DefaultStandard.swift index 87036912..5ead5990 100644 --- a/Sources/Spezi/Standard/DefaultStandard.swift +++ b/Sources/Spezi/Standard/DefaultStandard.swift @@ -7,4 +7,7 @@ // -actor DefaultStandard: Standard {} +@_spi(Spezi) +public actor DefaultStandard: Standard { + public init() {} +} diff --git a/Sources/XCTSpezi/DependencyResolution.swift b/Sources/XCTSpezi/DependencyResolution.swift index a2a4efb4..8cda4a18 100644 --- a/Sources/XCTSpezi/DependencyResolution.swift +++ b/Sources/XCTSpezi/DependencyResolution.swift @@ -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. From 276d94e39f9a0cc841be5db9b66ab86a79c5972a Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Fri, 8 Mar 2024 08:07:15 -0800 Subject: [PATCH 2/3] SPI import for tests as well --- Tests/SpeziTests/ModuleTests/ModuleBuilderTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SpeziTests/ModuleTests/ModuleBuilderTests.swift b/Tests/SpeziTests/ModuleTests/ModuleBuilderTests.swift index 3db5dab3..c6284b02 100644 --- a/Tests/SpeziTests/ModuleTests/ModuleBuilderTests.swift +++ b/Tests/SpeziTests/ModuleTests/ModuleBuilderTests.swift @@ -6,7 +6,7 @@ // SPDX-License-Identifier: MIT // -@testable import Spezi +@testable @_spi(Spezi) import Spezi import XCTest import XCTRuntimeAssertions From d6986157b3d4a2a0379c4116226447e6ae2b90a8 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Fri, 8 Mar 2024 08:09:10 -0800 Subject: [PATCH 3/3] Docs --- Sources/Spezi/Module/ModuleCollection.swift | 1 + Sources/Spezi/Spezi/Spezi.swift | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Sources/Spezi/Module/ModuleCollection.swift b/Sources/Spezi/Module/ModuleCollection.swift index 723c4a12..a273daea 100644 --- a/Sources/Spezi/Module/ModuleCollection.swift +++ b/Sources/Spezi/Module/ModuleCollection.swift @@ -11,6 +11,7 @@ /// /// You can not create a ``ModuleCollection`` yourself. Please use the ``ModuleBuilder`` to create a ``ModuleCollection``. public class ModuleCollection { + /// The elements of the collection. @_spi(Spezi) public let elements: [any Module] diff --git a/Sources/Spezi/Spezi/Spezi.swift b/Sources/Spezi/Spezi/Spezi.swift index a4c98115..62ac8afe 100644 --- a/Sources/Spezi/Spezi/Spezi.swift +++ b/Sources/Spezi/Spezi/Spezi.swift @@ -109,6 +109,13 @@ public class Spezi { self.init(standard: configuration.standard, modules: configuration.modules.elements, storage: storage) } + + /// 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,