Getting "dependency has no live implementation" warning for DependencyKey-conforming object #1745
-
I'm quite puzzled by what the runtime warning extension LocalPersistenceClient: DependencyKey {
private static let userSettingsKey = "co.pointfree.isowords.PersistenceClient.userSettings"
public static var liveValue: LocalPersistenceClient {
let defaultUserSettings = UserSettings()
var userSettings = UserDefaults.standard.data(forKey: userSettingsKey)
.flatMap({ try? decoder.decode(UserSettings.self, from: $0) }) ?? defaultUserSettings
{
didSet {
UserDefaults.standard.set(
try? encoder.encode(userSettings),
forKey: userSettingsKey
)
}
}
return Self(
userSettings: { userSettings },
setUserSettings: { newUserSettings in
userSettings = newUserSettings
}
)
}
} This error goes away if I explicitly set it in my AppReducer, but why is this even needed? @main class AppDelegate: UIResponder, UIApplicationDelegate {
let store = Store(
initialState: .init(),
reducer: AppMainReducer().transformDependency(\.self) {
$0.localPersistenceClient = .liveValue
}
)
} Isowords does something similar but only for 3 dependencies: https://github.com/pointfreeco/isowords/blob/main/App/iOS/App.swift#L15. What makes those 3 dependencies special enough to require being explicitly set and not the many, many other dependencies that exist in the app? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey @acosmicflamingo! This is maybe related to #1640. Maybe you can try to reference |
Beta Was this translation helpful? Give feedback.
-
Hi @tgrapperon ! Oh that does seems exactly like what is happening with me :) I'm using Tuist to handle my app/module/etc, so this makes sense. Thank you! |
Beta Was this translation helpful? Give feedback.
Hey @acosmicflamingo! This is maybe related to #1640. Maybe you can try to reference
.liveValue
in the same file asAppDelegate
(even without assigning it to your reducer). This is not optimal, but it's maybe enough for the compiler to pick it up.