From b7510c3dbc34f33add28b47c7abb2a488c65f476 Mon Sep 17 00:00:00 2001 From: Andreas Bauer Date: Thu, 20 Jul 2023 13:58:37 +0200 Subject: [PATCH] Fix swiftlint --- .../SharedRepository/SharedRepository.swift | 25 ++++++++++++++++--- .../HelperTests/SharedRepositoryTests.swift | 3 ++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Sources/Spezi/SharedRepository/SharedRepository.swift b/Sources/Spezi/SharedRepository/SharedRepository.swift index 543f3258..95518bb9 100644 --- a/Sources/Spezi/SharedRepository/SharedRepository.swift +++ b/Sources/Spezi/SharedRepository/SharedRepository.swift @@ -68,26 +68,41 @@ public protocol SharedRepository { /// - Returns: The stored ``KnowledgeSource/Value`` or the ``DefaultProvidingKnowledgeSource/defaultValue``. subscript>(_ source: Source.Type) -> Source.Value { get } - /// A subscript to retrieve or set a ``ComputedKnowledgeSource``. + /// A subscript to retrieve a ``ComputedKnowledgeSource``. /// - /// - Note: If the value was not present and got computed, the computed value will be stored in the repository. + /// - Note: This is the implementation for the ``ComputedKnowledgeSource/Store`` policy. + /// If the value was not present and got computed, the computed value will be stored in the repository. /// - Parameter source: The ``ComputedKnowledgeSource`` type. /// - Returns: The stored ``KnowledgeSource/Value`` or calls ``ComputedKnowledgeSource/compute(from:)`` to compute the value. subscript>(_ source: Source.Type) -> Source.Value where Source.StoragePolicy == _StoreComputePolicy { mutating get } + /// A subscript to retrieve a ``ComputedKnowledgeSource``. + /// + /// - Note: This is the implementation for the ``ComputedKnowledgeSource/AlwaysCompute`` policy. + /// The ``ComputedKnowledgeSource/compute(from:)`` method will always be called as a result of this subscript call. + /// - Parameter source: The ``ComputedKnowledgeSource`` type. + /// - Returns: The calls ``ComputedKnowledgeSource/compute(from:)`` to compute the value. subscript>(_ source: Source.Type) -> Source.Value where Source.StoragePolicy == _AlwaysComputePolicy { get } - /// A subscript to retrieve or set a ``OptionalComputedKnowledgeSource``. + /// A subscript to retrieve a ``OptionalComputedKnowledgeSource``. /// - /// - Note: If the value was not present and got computed, the computed value will be stored in the repository. + /// - Note: This is the implementation for the ``OptionalComputedKnowledgeSource/Store`` policy. + /// If the value was not present and got computed, the computed value will be stored in the repository. /// - Parameter source: The ``OptionalComputedKnowledgeSource`` type. /// - Returns: The stored ``KnowledgeSource/Value`` or calls ``OptionalComputedKnowledgeSource/compute(from:)`` to compute the value /// or `nil` if the `compute` method returned nil. subscript>(_ source: Source.Type) -> Source.Value? where Source.StoragePolicy == _StoreComputePolicy { mutating get } + /// A subscript to retrieve a ``OptionalComputedKnowledgeSource``. + /// + /// - Note: This is the implementation for the ``OptionalComputedKnowledgeSource/AlwaysCompute`` policy. + /// The ``OptionalComputedKnowledgeSource/compute(from:)`` method will always be called as a result of this subscript call. + /// - Parameter source: The ``OptionalComputedKnowledgeSource`` type. + /// - Returns: The calls ``OptionalComputedKnowledgeSource/compute(from:)`` to compute the value + /// or `nil` if the `compute` method returned nil. subscript>(_ source: Source.Type) -> Source.Value? where Source.StoragePolicy == _AlwaysComputePolicy { get } } @@ -129,6 +144,7 @@ extension SharedRepository { } } + /// Default subscript implementation delegating calling ``ComputedKnowledgeSource/compute(from:)``. public subscript>(_ source: Source.Type) -> Source.Value where Source.StoragePolicy == _AlwaysComputePolicy { source.compute(from: self) @@ -149,6 +165,7 @@ extension SharedRepository { } } + /// Default subscript implementation delegating calling ``OptionalComputedKnowledgeSource/compute(from:)``. public subscript>(_ source: Source.Type) -> Source.Value? where Source.StoragePolicy == _AlwaysComputePolicy { source.compute(from: self) diff --git a/Tests/SpeziTests/HelperTests/SharedRepositoryTests.swift b/Tests/SpeziTests/HelperTests/SharedRepositoryTests.swift index 07add99c..f7c1f9aa 100644 --- a/Tests/SpeziTests/HelperTests/SharedRepositoryTests.swift +++ b/Tests/SpeziTests/HelperTests/SharedRepositoryTests.swift @@ -254,10 +254,11 @@ final class SharedRepositoryTests: XCTestCase { } } - private var repos: [AnyTestInstance] = [] static var computedValue: Int = 3 static var optionalComputedValue: Int? + private var repos: [AnyTestInstance] = [] + override func setUp() { repos = [TestInstance(HeapRepository()), TestInstance(ValueRepository())] Self.computedValue = 3