Property wrappers + dependency injection: why do I need a setter here?

I think it's because you're storing an existential (aka protocol type), Settings (which needs to be spelled any Settings in Swift 6 FYI, and you can and should adopt this spelling today), and existentials are value types?

If you remove the as Settings and change the settings property to be SettingsDatasource then it seems to work. Perhaps you could use a super class instead of a protocol.

Or you could try to make it work with keypaths like SwiftUI's @Environment, or a similar solution that was recently shared here: Dictionary with types as keys and different type values? - #13 by Jon_Shier

1 Like