Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update runtime warning for no liveValue. #206

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,29 @@ let package = Package(
.product(name: "CombineSchedulers", package: "combine-schedulers"),
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "DependenciesTests",
dependencies: [
"Dependencies",
"DependenciesMacros",
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.target(
name: "DependenciesMacros",
dependencies: [
"DependenciesMacrosPlugin",
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.macro(
Expand Down Expand Up @@ -96,6 +105,9 @@ let package = Package(
dependencies: [
"DependenciesMacrosPlugin",
.product(name: "MacroTesting", package: "swift-macro-testing"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
])
Expand Down
13 changes: 8 additions & 5 deletions Sources/Dependencies/DependencyValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,15 @@ private final class CachedValues: @unchecked Sendable {

\(dependencyDescription)

Every dependency registered with the library must conform to 'DependencyKey', and \
that conformance must be visible to the running application.
To fix you can do one of two things:

To fix, make sure that '\(typeName(Key.self))' conforms to 'DependencyKey' by \
providing a live implementation of your dependency, and make sure that the \
conformance is linked with this current application.
* Conform '\(typeName(Key.self))' to the 'DependencyKey' protocol by providing \
a live implementation of your dependency, and make sure that the conformance is \
linked with this current application.

* Override the implementation of '\(typeName(Key.self))' using 'withDependencies'. \
This is typically done at the entry point of your application, but can be done \
later too.
""",
file: DependencyValues.currentDependency.file ?? file,
line: DependencyValues.currentDependency.line ?? line
Expand Down
14 changes: 8 additions & 6 deletions Sources/Dependencies/WithDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public func withDependencies<Model: AnyObject, R>(
else {
runtimeWarn(
"""
You are trying to propagate dependencies to a child model from a model with no \
dependencies. To fix this, the given '\(Model.self)' must be returned from another \
'withDependencies' closure, or the class must hold at least one '@Dependency' property.
You are trying to propagate dependencies to a child model from a model with no dependencies. \
To fix this, the given '\(Model.self)' must be returned from another 'withDependencies' \
closure, or the class must hold at least one '@Dependency' property.
""",
file: file,
line: line
Expand Down Expand Up @@ -326,8 +326,8 @@ private class DependencyObjects: @unchecked Sendable {
internal init() {}

func store(_ object: AnyObject) {
self.storage.withValue { storage in
storage[ObjectIdentifier(object)] = DependencyObject(
self.storage.withValue { [id = ObjectIdentifier(object)] storage in
storage[id] = DependencyObject(
object: object,
dependencyValues: DependencyValues._current
)
Expand All @@ -347,7 +347,9 @@ private class DependencyObjects: @unchecked Sendable {
.compactMap({ $1 as? _HasInitialValues })
.first?
.initialValues
?? self.storage.withValue({ $0[ObjectIdentifier(object)]?.dependencyValues })
?? self.storage.withValue({ [id = ObjectIdentifier(object)] in
$0[id]?.dependencyValues
})
}
}

Expand Down
Loading