diff --git a/README.md b/README.md index 1f99113f..75676892 100644 --- a/README.md +++ b/README.md @@ -164,15 +164,15 @@ and `UUID()`, and we'd have to wait for real world time to pass, making the test But, controllable dependencies aren't only useful for tests. They can also be used in Xcode previews. Suppose the feature above makes use of a clock to sleep for an amount of time before something happens in the view. If you don't want to literally wait for time to pass in order to see -how the view changes, you can override the clock dependency to be an "immediate" clock using the -`.dependencies` preview trait: +how the view changes, you can override the clock dependency to be an "immediate" clock using +`prepareDependencies`: ```swift -#Preview( - traits: .dependencies { +#Preview { + let _ = prepareDependencies { $0.continuousClock = .immediate } -) { + // All access of '@Dependency(\.continuousClock)' in this preview will // use an immediate clock. FeatureView(model: FeatureModel()) @@ -267,7 +267,8 @@ If you want to discuss this library or have a question about how to use it to so a particular problem, there are a number of places you can discuss with fellow [Point-Free](http://www.pointfree.co) enthusiasts: -* For long-form discussions, we recommend the [discussions](http://github.com/pointfreeco/swift-dependencies/discussions) tab of this repo. +* For long-form discussions, we recommend the + [discussions](http://github.com/pointfreeco/swift-dependencies/discussions) tab of this repo. * For casual chat, we recommend the [Point-Free Community Slack](http://pointfree.co/slack-invite). ## Extensions @@ -277,7 +278,8 @@ following projects all build on top of Dependencies: * [Dependencies Additions](https://github.com/tgrapperon/swift-dependencies-additions): A companion library that provides higher-level dependencies. - * [Dependencies Protocol Extras](https://github.com/arasan01/swift-dependencies-extras): Library to make swift-dependencies even more useful when using Protocol + * [Dependencies Protocol Extras](https://github.com/arasan01/swift-dependencies-extras): A library + to make swift-dependencies even more useful when using protocols. ## Alternatives @@ -310,5 +312,5 @@ This library is released under the MIT license. See [LICENSE](LICENSE) for detai [syncups-demo]: https://github.com/pointfreeco/syncups [swiftui-nav-gh]: http://github.com/pointfreeco/swiftui-navigation [dep-values-docs]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/dependencyvalues#dependency-values -[withdependencies-docs]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/withdependencies(_:operation:)-4uz6m +[withdependencies-docs]: https://swiftpackageindex.com/pointfreeco/swift-dependencies/main/documentation/dependencies/withdependencies(isolation:_:operation:) [immediate-clock-docs]: https://pointfreeco.github.io/swift-clocks/main/documentation/clocks/immediateclock diff --git a/Sources/Dependencies/Dependency.swift b/Sources/Dependencies/Dependency.swift index 9c6884f6..69b8ab23 100644 --- a/Sources/Dependencies/Dependency.swift +++ b/Sources/Dependencies/Dependency.swift @@ -122,7 +122,12 @@ /// } /// ``` /// - /// - Parameter keyPath: A key path to a specific resulting value. + /// - Parameters + /// - keyPath: A key path to a specific resulting value. + /// - fileID: The source `#fileID` associated with the dependency. + /// - filePath: The source `#filePath` associated with the dependency. + /// - line: The source `#line` associated with the dependency. + /// - column: The source `#column` associated with the dependency. public init( _ keyPath: KeyPath & Sendable, fileID: StaticString = #fileID, @@ -174,7 +179,12 @@ extension Dependency { /// } /// ``` /// - /// - Parameter key: A dependency key to a specific resulting value. + /// - Parameters + /// - key: A dependency key to a specific resulting value. + /// - fileID: The source `#fileID` associated with the dependency. + /// - filePath: The source `#filePath` associated with the dependency. + /// - line: The source `#line` associated with the dependency. + /// - column: The source `#column` associated with the dependency. public init( _ key: Key.Type, fileID: StaticString = #fileID, @@ -233,19 +243,19 @@ extension DependencyValues { get { self[ Key.self, - key.fileID, - key.filePath, - key.line, - key.column + fileID: key.fileID, + filePath: key.filePath, + line: key.line, + column: key.column ] } set { self[ Key.self, - key.fileID, - key.filePath, - key.line, - key.column + fileID: key.fileID, + filePath: key.filePath, + line: key.line, + column: key.column ] = newValue } } diff --git a/Sources/Dependencies/DependencyValues.swift b/Sources/Dependencies/DependencyValues.swift index 889795c3..64642552 100644 --- a/Sources/Dependencies/DependencyValues.swift +++ b/Sources/Dependencies/DependencyValues.swift @@ -224,11 +224,11 @@ public struct DependencyValues: Sendable { /// property wrapper. public subscript( key: Key.Type, - fileID: StaticString = #fileID, - filePath: StaticString = #filePath, - line: UInt = #line, - column: UInt = #line, - function: StaticString = #function + fileID fileID: StaticString = #fileID, + filePath filePath: StaticString = #filePath, + line line: UInt = #line, + column column: UInt = #line, + function function: StaticString = #function ) -> Key.Value { get { guard let base = self.storage[ObjectIdentifier(key)], let dependency = base as? Key.Value diff --git a/Sources/Dependencies/Documentation.docc/Articles/Lifetimes.md b/Sources/Dependencies/Documentation.docc/Articles/Lifetimes.md index e48f7760..f46ef843 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/Lifetimes.md +++ b/Sources/Dependencies/Documentation.docc/Articles/Lifetimes.md @@ -190,7 +190,7 @@ the scope of the `operation` closure. However, care must be taken when creating a child model from a parent model. In order for the child's dependencies to inherit from the parent's dependencies, you must make use of -``withDependencies(from:operation:file:line:)-8e74m`` when creating the child model: +``withDependencies(from:operation:fileID:filePath:line:column:)`` when creating the child model: ```swift let onboardingModel = withDependencies(from: self) { @@ -205,7 +205,7 @@ override any additional dependencies you want. In general, if you want dependencies to be properly inherited through every layer of feature in your application, you should make sure to create any observable models inside a -``withDependencies(from:operation:file:line:)-8e74m`` scope. +``withDependencies(from:operation:fileID:filePath:line:column:)`` scope. If you do this, it also allows you to run previews in a very specific environment. Dependencies already support the concept of a ``TestDependencyKey/previewValue-8u2sy``, which is an @@ -218,11 +218,10 @@ feature behaves in very specific states. For example, if you wanted to see how y when the `fetchUser` endpoint throws an error, you can update the preview like so: ```swift -#Preview( - traits: .dependencies { +#Preview { + let _ = prepareDependencies { $0.apiClient.fetchUser = { _ in throw SomeError() } } -) { FeatureView(model: FeatureModel()) } ``` diff --git a/Sources/Dependencies/Documentation.docc/Articles/OverridingDependencies.md b/Sources/Dependencies/Documentation.docc/Articles/OverridingDependencies.md index fd56dc39..8f1242d4 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/OverridingDependencies.md +++ b/Sources/Dependencies/Documentation.docc/Articles/OverridingDependencies.md @@ -18,9 +18,10 @@ be written to disk, or user defaults to be written, or any number of things. It use mock versions of those dependencies so that the user can interact with your feature in a fully controlled environment. -To do this you need to make use of the ``withDependencies(from:_:operation:file:line:)-2y5dq`` -method, which allows you to inherit the dependencies from an existing object _and_ additionally -override some of those dependencies: +To do this you need to make use of the +``withDependencies(from:operation:fileID:filePath:line:column:)`` function, which allows you to +inherit the dependencies from an existing object _and_ additionally override some of those +dependencies: ```swift @Observable @@ -48,8 +49,8 @@ interact with the outside world. This way you can be sure that while the user is the tutorial sandbox they are not accidentally making network requests, saving data to disk or overwriting settings in user defaults. -> Note: The method ``withDependencies(from:_:operation:file:line:)-262kg`` used in the code snippet -> above is subtly different from ``withDependencies(_:operation:)-3vrqy``. It takes an extra +> Note: The method ``withDependencies(from:operation:fileID:filePath:line:column:)`` used in the +> code snippet above is subtly different from ``withDependencies(_:operation:)``. It takes an extra > argument, `from`, which is the object from which we propagate the dependencies before overriding > some. This allows you to propagate dependencies from object to object. > @@ -60,7 +61,7 @@ overwriting settings in user defaults. Extra care must be taken when overriding dependencies in order for the new dependencies to propagate down to child models, and grandchild models, and on and on. All child models constructed should be -done so inside an invocation of ``withDependencies(from:operation:file:line:)-8e74m`` so +done so inside an invocation of ``withDependencies(from:operation:fileID:filePath:line:column:)`` so that the child model picks up the exact dependencies the parent is using. For example, taking the code sample from above, suppose that the `TodosModel` could drill down to an @@ -94,7 +95,7 @@ any of the overridden dependencies from when the `TodosModel` was created. In order to make sure the overridden dependencies continue to propagate to the child feature, you must wrap the creation of the child model in -``withDependencies(from:operation:file:line:)-8e74m``: +``withDependencies(from:operation:fileID:filePath:line:column:)``: ```swift func tappedTodo(_ todo: Todo) { diff --git a/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md b/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md index 2edd39c3..c5b048fc 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md +++ b/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md @@ -118,20 +118,18 @@ and `UUID()`, and we'd have to wait for real world time to pass, making the test But, controllable dependencies aren't only useful for tests. They can also be used in Xcode previews. Suppose the feature above makes use of a clock to sleep for an amount of time before something happens in the view. If you don't want to literally wait for time to pass in order to see -how the view changes, you can override the clock dependency to be an "immediate" clock using the -``withDependencies(_:operation:)-4uz6m`` helper: +how the view changes, you can override the clock dependency to be an "immediate" clock using +``prepareDependencies(_:)``: ```swift -struct Feature_Previews: PreviewProvider { - static var previews: some View { - FeatureView( - model: withDependencies { - $0.clock = ImmediateClock() - } operation: { - FeatureModel() - } - ) +#Preview { + let _ = prepareDependencies { + $0.continuousClock = .immediate } + + // All access of '@Dependency(\.continuousClock)' in this preview will + // use an immediate clock. + FeatureView(model: FeatureModel()) } ``` diff --git a/Sources/Dependencies/Documentation.docc/Articles/RegisteringDependencies.md b/Sources/Dependencies/Documentation.docc/Articles/RegisteringDependencies.md index 657ca00e..fad9ee0c 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/RegisteringDependencies.md +++ b/Sources/Dependencies/Documentation.docc/Articles/RegisteringDependencies.md @@ -26,7 +26,7 @@ extension APIClient: DependencyKey { ``` > Tip: There are two other values you can provide for a dependency. If you implement -> ``DependencyKey/testValue-5v726`` it will be used when running features in tests, and if you +> ``DependencyKey/testValue`` it will be used when running features in tests, and if you > implement `previewValue` it will be used while running features in an Xcode preview. You don't > need to worry about those values when you are just getting started, and instead can add them > later. See for more information. diff --git a/Sources/Dependencies/Documentation.docc/Articles/SingleEntryPointSystems.md b/Sources/Dependencies/Documentation.docc/Articles/SingleEntryPointSystems.md index 298bb2df..76220cdf 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/SingleEntryPointSystems.md +++ b/Sources/Dependencies/Documentation.docc/Articles/SingleEntryPointSystems.md @@ -43,8 +43,7 @@ struct Feature { enum Action { // ... } - - func reduce(into state: inout State, action: Action) -> EffectTask { + var body: some Reducer { // All of the feature's logic and behavior is implemented here... } } @@ -132,8 +131,7 @@ struct Feature { enum Action { // ... } - - var body: some ReducerOf { + var body: some Reducer { Header() .dependency(\.fileManager, .mock) .dependency(\.userDefaults, .mock) @@ -193,7 +191,7 @@ to the child. For example, if your SwiftUI model holds a piece of optional state that drives a sheet, then when hydrating that state you will want to wrap it in -``withDependencies(from:operation:file:line:)-8e74m``: +``withDependencies(from:operation:fileID:filePath:line:column:)``: ```swift @Observable @@ -218,7 +216,7 @@ This makes it so that if `FeatureModel` were constructed with some of its depend The same principle holds for UIKit. When constructing a child view controller to be presented, be sure to wrap its construction in -``withDependencies(from:operation:file:line:)-8e74m``: +``withDependencies(from:operation:fileID:filePath:line:column:)``: ```swift final class FeatureViewController: UIViewController { @@ -234,7 +232,7 @@ final class FeatureViewController: UIViewController { } ``` -If you make sure to always use ``withDependencies(from:operation:file:line:)-8e74m`` +If you make sure to always use ``withDependencies(from:operation:fileID:filePath:line:column:)`` when constructing child models and controllers you can be sure that changes to dependencies at any layer of your application will be visible at any layer below it. See for more information on how dependency lifetimes work. diff --git a/Sources/Dependencies/Documentation.docc/Articles/Testing.md b/Sources/Dependencies/Documentation.docc/Articles/Testing.md index 29efe3b6..86bc265e 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/Testing.md +++ b/Sources/Dependencies/Documentation.docc/Articles/Testing.md @@ -22,7 +22,7 @@ great for tests. It means your feature doesn't need to actually make network req how your feature deals with data returned from an API, and your feature doesn't need to interact with the file system just to test how data gets loaded or persisted. -The tool for doing this is ``withDependencies(_:operation:)-3vrqy``, which allows you to specify +The tool for doing this is ``withDependencies(_:operation:)``, which allows you to specify which dependencies should be overridden for the test, and then construct your feature's model in that context: @@ -49,7 +49,8 @@ the date is "Feb 13, 2009 at 3:31 PM". > models inside its methods, then it has to be careful about how it does so. In order for > `FeatureModel`'s dependencies to propagate to the new child model, it must construct the child > model in an altered execution context that passes along the dependencies. The tool for this is -> ``withDependencies(from:operation:file:line:)-2qx0c`` and can be used simply like this: +> ``withDependencies(from:operation:fileID:filePath:line:column:)`` and can be used simply like +> this: > > ```swift > @Observable @@ -78,7 +79,7 @@ For example, suppose we have a login feature such that if you try logging in and causing a message to appear. But then later, if login succeeds that message goes away. We can test that entire flow, from end-to-end, but starting the API client dependency in a state where login fails, and then later change the dependency so that it succeeds using -``withDependencies(_:operation:)-3vrqy``: +``withDependencies(_:operation:)``: ```swift @Test @@ -242,7 +243,7 @@ still features missing from the Testing framework that XCTest has, there may be steps you must take. If you are are writing a _parameterized_ test using the `@Test` macro, you will need to surround the -entire body of your test in [`withDependencies`]() that +entire body of your test in [`withDependencies`]() that resets the entire set of values to guarantee that a fresh set of dependencies is used per parameter: ```swift diff --git a/Sources/Dependencies/Documentation.docc/Articles/WhatAreDependencies.md b/Sources/Dependencies/Documentation.docc/Articles/WhatAreDependencies.md index fc4beebe..c9454fd9 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/WhatAreDependencies.md +++ b/Sources/Dependencies/Documentation.docc/Articles/WhatAreDependencies.md @@ -104,16 +104,11 @@ For previews, you can use the `.dependencies` preview trait to override the does not actually sleep for any amount of time: ```swift -#Preview( - .dependencies { $0.continuousClock = .immediate } -) { - FeatureView( - model: withDependencies { - $0.continuousClock = ImmediateClock() - } operation: { - FeatureModel() - } - ) +#Preview { + let _ = prepareDependencies { + $0.continuousClock = .immediate + } + FeatureView(model: FeatureModel()) } ``` diff --git a/Sources/Dependencies/Documentation.docc/Dependencies.md b/Sources/Dependencies/Documentation.docc/Dependencies.md index a0b11370..ffd002e7 100644 --- a/Sources/Dependencies/Documentation.docc/Dependencies.md +++ b/Sources/Dependencies/Documentation.docc/Dependencies.md @@ -79,9 +79,3 @@ This library addresses all of the points above, and much, _much_ more. - ``DependencyValues`` - ``DependencyKey`` - ``DependencyContext`` - -### Concurrency support - -- ``ActorIsolated`` -- ``LockIsolated`` -- ``UncheckedSendable`` diff --git a/Sources/Dependencies/Documentation.docc/Extensions/Dependency.md b/Sources/Dependencies/Documentation.docc/Extensions/Dependency.md index 1d37e7fa..615a1169 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/Dependency.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/Dependency.md @@ -4,7 +4,8 @@ ### Using a dependency -- ``init(_:fileID:filePath:line:column:)`` +- ``init(_:fileID:filePath:line:column:)-1f0mh`` +- ``init(_:fileID:filePath:line:column:)-1ytea`` ### Getting the value diff --git a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValues.md b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValues.md index 8126b78e..6ff73e24 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValues.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValues.md @@ -5,12 +5,14 @@ ### Creating and accessing values - ``init()`` -- ``subscript(key:file:function:line:) +- ``subscript(_:fileID:filePath:line:column:function:)`` +- ``subscript(_:)`` ### Overriding values - ``withDependencies(_:operation:)-4uz6m`` -- ``withDependencies(from:operation:file:line:)-8e74m`` +- ``withDependencies(from:operation:fileID:filePath:line:column:)`` +- ``prepareDependencies(_:)`` ### Escaping contexts diff --git a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesAssert.md b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesAssert.md index a5b37d30..8864555d 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesAssert.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesAssert.md @@ -6,7 +6,3 @@ - ``AssertionEffect`` - ``AssertionFailureEffect`` - -### Custom assertions - -- ``AnyAssertionEffect`` diff --git a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesDeprecations.md b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesDeprecations.md index 336640a8..40d8b68b 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesDeprecations.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesDeprecations.md @@ -12,8 +12,8 @@ instead. ### Overriding values - ``DependencyValues/withTestValues(_:assert:)-6erij`` -- ``DependencyValues/withTestValues(_:assert:)-1egh6`` +- ``DependencyValues/withTestValues(_:assert:)-6qwh1`` - ``DependencyValues/withValues(_:operation:)-9prz8`` -- ``DependencyValues/withValues(_:operation:)-4pas8`` +- ``DependencyValues/withValues(_:operation:)-4omsq`` - ``DependencyValues/withValue(_:_:operation:)-4lu7m`` -- ``DependencyValues/withValue(_:_:operation:)-2ewcx`` +- ``DependencyValues/withValue(_:_:operation:)-65nv4`` diff --git a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesUUID.md b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesUUID.md index cae008e6..462d3362 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesUUID.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/DependencyValuesUUID.md @@ -5,3 +5,7 @@ ### Dependency value - ``UUIDGenerator`` + +### Helpers + +- ``Foundation/UUID`` diff --git a/Sources/Dependencies/Documentation.docc/Extensions/WithDependencies.md b/Sources/Dependencies/Documentation.docc/Extensions/WithDependencies.md index d4c62507..661da835 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/WithDependencies.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/WithDependencies.md @@ -1,7 +1,7 @@ -# ``Dependencies/withDependencies(_:operation:)-4uz6m`` +# ``Dependencies/withDependencies(_:operation:)`` ## Topics ### Overloads -- ``withDependencies(_:operation:)-3vrqy`` +- ``withDependencies(isolation:_:operation:)`` diff --git a/Sources/Dependencies/Documentation.docc/Extensions/WithDependenciesFrom.md b/Sources/Dependencies/Documentation.docc/Extensions/WithDependenciesFrom.md index 6a730eb6..79259e8e 100644 --- a/Sources/Dependencies/Documentation.docc/Extensions/WithDependenciesFrom.md +++ b/Sources/Dependencies/Documentation.docc/Extensions/WithDependenciesFrom.md @@ -1,9 +1,9 @@ -# ``Dependencies/withDependencies(from:operation:file:line:)-8e74m`` +# ``Dependencies/withDependencies(from:operation:fileID:filePath:line:column:)`` ## Topics ### Overloads -- ``withDependencies(from:operation:file:line:)-2qx0c`` -- ``withDependencies(from:_:operation:file:line:)-2y5dq`` -- ``withDependencies(from:_:operation:file:line:)-262kg`` +- ``withDependencies(from:isolation:operation:fileID:filePath:line:column:)`` +- ``withDependencies(from:_:operation:fileID:filePath:line:column:)`` +- ``withDependencies(from:isolation:_:operation:fileID:filePath:line:column:)`` diff --git a/Sources/Dependencies/Internal/AppEntryPoint.swift b/Sources/Dependencies/Internal/AppEntryPoint.swift index 4b66109b..980c013f 100644 --- a/Sources/Dependencies/Internal/AppEntryPoint.swift +++ b/Sources/Dependencies/Internal/AppEntryPoint.swift @@ -1,7 +1,7 @@ import Foundation extension Thread { - public static var isPreviewAppEntryPoint: Bool { + static var isPreviewAppEntryPoint: Bool { guard ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" else { return false } diff --git a/Sources/Dependencies/Internal/Deprecations.swift b/Sources/Dependencies/Internal/Deprecations.swift index 33eee6b9..9f1234f9 100644 --- a/Sources/Dependencies/Internal/Deprecations.swift +++ b/Sources/Dependencies/Internal/Deprecations.swift @@ -1,7 +1,59 @@ +// MARK: - Deprecated after 1.6.3 + +#if canImport(SwiftUI) && compiler(>=6) + import SwiftUI + + @available(iOS 18, macOS 15, tvOS 18, watchOS 11, visionOS 2, *) + extension PreviewTrait where T == Preview.ViewTraits { + @available( + *, deprecated, message: """ + Use 'withDependencies' or 'prepareDependencies' from the body of the preview, instead. + """ + ) + @_documentation(visibility:private) + public static func dependency( + _ keyPath: WritableKeyPath & Sendable, + _ value: Value + ) -> PreviewTrait { + .dependencies { $0[keyPath: keyPath] = value } + } + + @available( + *, deprecated, message: """ + Use 'withDependencies' or 'prepareDependencies' from the body of the preview, instead. + """ + ) + @_documentation(visibility:private) + public static func dependency( + _ value: Value + ) -> PreviewTrait where Value == Value.Value { + .dependencies { $0[Value.self] = value } + } + + @available( + *, deprecated, message: """ + Use 'withDependencies' or 'prepareDependencies' from the body of the preview, instead. + """ + ) + @_documentation(visibility:private) + public static func dependencies( + _ updateValuesForPreview: (inout DependencyValues) -> Void + ) -> PreviewTrait { + var copy = previewValues + defer { previewValues = copy } + updateValuesForPreview(©) + return PreviewTrait() + } + } + + nonisolated(unsafe) var previewValues = DependencyValues(context: .preview) +#endif + // MARK: - Deprecated after 0.4.2 extension AsyncStream { @available(*, deprecated, renamed: "makeStream(of:bufferingPolicy:)") + @_documentation(visibility:private) public static func streamWithContinuation( _ elementType: Element.Type = Element.self, bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded @@ -13,6 +65,7 @@ extension AsyncStream { extension AsyncThrowingStream where Failure == Error { @available(*, deprecated, renamed: "makeStream(of:throwing:bufferingPolicy:)") + @_documentation(visibility:private) public static func streamWithContinuation( _ elementType: Element.Type = Element.self, bufferingPolicy limit: Continuation.BufferingPolicy = .unbounded @@ -30,6 +83,7 @@ extension ActorIsolated { deprecated, message: "Use the non-async version of 'withValue'." ) + @_documentation(visibility:private) public func withValue( _ operation: @Sendable (inout Value) async throws -> T ) async rethrows -> T where Value: Sendable { @@ -45,6 +99,7 @@ extension AsyncStream where Element: Sendable { deprecated, message: "Do not configure streams with a buffering policy 'limit' parameter." ) + @_documentation(visibility:private) public init( _ sequence: S, bufferingPolicy limit: Continuation.BufferingPolicy @@ -74,6 +129,7 @@ extension AsyncThrowingStream where Element: Sendable, Failure == Error { deprecated, message: "Do not configure streams with a buffering policy 'limit' parameter." ) + @_documentation(visibility:private) public init( _ sequence: S, bufferingPolicy limit: Continuation.BufferingPolicy diff --git a/Sources/Dependencies/Traits/PreviewTrait.swift b/Sources/Dependencies/Traits/PreviewTrait.swift index b9af8f9a..8b137891 100644 --- a/Sources/Dependencies/Traits/PreviewTrait.swift +++ b/Sources/Dependencies/Traits/PreviewTrait.swift @@ -1,67 +1 @@ -#if canImport(SwiftUI) && compiler(>=6) - import SwiftUI - @available(iOS 18, macOS 15, tvOS 18, watchOS 11, visionOS 2, *) - extension PreviewTrait where T == Preview.ViewTraits { - /// A trait that overrides a preview's dependency. - /// - /// Useful for overriding a dependency in a preview without incurring the nesting and - /// indentation of ``withDependencies(_:operation:)-4uz6m``. - /// - /// ```swift - /// #Preview( - /// .dependency(\.continuousClock, .immediate) - /// ) { - /// TimerView() - /// } - /// ``` - /// - /// - Parameters: - /// - keyPath: A key path to a dependency value. - /// - value: A dependency value to override for the lifetime of the preview. - public static func dependency( - _ keyPath: WritableKeyPath & Sendable, - _ value: Value - ) -> PreviewTrait { - .dependencies { $0[keyPath: keyPath] = value } - } - - /// A trait that overrides a preview's dependency. - /// - /// - Parameter value: A dependency value to override for the test. - public static func dependency( - _ value: Value - ) -> PreviewTrait where Value == Value.Value { - .dependencies { $0[Value.self] = value } - } - - /// A trait that overrides a preview's dependencies. - /// - /// Useful for overriding several dependencies in a preview without incurring the nesting and - /// indentation of ``withDependencies(_:operation:)-4uz6m``. - /// - /// ```swift - /// #Preview( - /// .dependencies { - /// $0.continuousClock = .immediate - /// $0.date.now = Date(timeIntervalSinceReferenceDate: 0) - /// } - /// ) { - /// TimerView() - /// } - /// ``` - /// - /// - Parameter updateValuesForPreview: A closure for updating the current dependency values for - /// the lifetime of the preview. - public static func dependencies( - _ updateValuesForPreview: (inout DependencyValues) -> Void - ) -> PreviewTrait { - var copy = previewValues - defer { previewValues = copy } - updateValuesForPreview(©) - return PreviewTrait() - } - } - - nonisolated(unsafe) var previewValues = DependencyValues(context: .preview) -#endif diff --git a/Sources/Dependencies/WithDependencies.swift b/Sources/Dependencies/WithDependencies.swift index 6ccaccd6..24c800d9 100644 --- a/Sources/Dependencies/WithDependencies.swift +++ b/Sources/Dependencies/WithDependencies.swift @@ -105,6 +105,7 @@ public func withDependencies( /// ``` /// /// - Parameters: + /// - isolation: The isolation associated with the operation. /// - updateValuesForOperation: A closure for updating the current dependency values for the /// duration of the operation. /// - operation: An operation to perform wherein dependencies have been overridden. @@ -173,6 +174,10 @@ public func withDependencies( /// - updateValuesForOperation: A closure for updating the current dependency values for the /// duration of the operation. /// - operation: The operation to run with the updated dependencies. +/// - fileID: The source `#fileID` associated with the operation. +/// - filePath: The source `#filePath` associated with the operation. +/// - line: The source `#line` associated with the operation. +/// - column: The source `#column` associated with the operation. /// - Returns: The result returned from `operation`. @discardableResult public func withDependencies( @@ -218,6 +223,10 @@ public func withDependencies( /// - model: An object with dependencies. The given model should have at least one `@Dependency` /// property, or should have been initialized and returned from a `withDependencies` operation. /// - operation: The operation to run with the updated dependencies. +/// - fileID: The source `#fileID` associated with the operation. +/// - filePath: The source `#filePath` associated with the operation. +/// - line: The source `#line` associated with the operation. +/// - column: The source `#column` associated with the operation. /// - Returns: The result returned from `operation`. @discardableResult public func withDependencies( @@ -247,9 +256,14 @@ public func withDependencies( /// - model: An object with dependencies. The given model should have at least one `@Dependency` /// property, or should have been initialized and returned from a `withDependencies` /// operation. + /// - isolation: The isolation associated with the operation. /// - updateValuesForOperation: A closure for updating the current dependency values for the /// duration of the operation. /// - operation: The operation to run with the updated dependencies. + /// - fileID: The source `#fileID` associated with the operation. + /// - filePath: The source `#filePath` associated with the operation. + /// - line: The source `#line` associated with the operation. + /// - column: The source `#column` associated with the operation. /// - Returns: The result returned from `operation`. @discardableResult public func withDependencies( @@ -296,7 +310,12 @@ public func withDependencies( /// - model: An object with dependencies. The given model should have at least one `@Dependency` /// property, or should have been initialized and returned from a `withDependencies` /// operation. + /// - isolation: The isolation associated with the operation. /// - operation: The operation to run with the updated dependencies. + /// - fileID: The source `#fileID` associated with the operation. + /// - filePath: The source `#filePath` associated with the operation. + /// - line: The source `#line` associated with the operation. + /// - column: The source `#column` associated with the operation. /// - Returns: The result returned from `operation`. @discardableResult public func withDependencies(