Conform UserDefaults (and UserDefaultsClient) to UserDefaultsProtocol.
The solution enables custom UserDefaults implementations, such as UserDefaultsClient, to integrate seamlessly with the SDK, enhancing flexibility without introducing breaking changes to the public API.
Our app uses a custom
UserDefaultsClient
interface to manageUserDefaults
, defined as follows:The SDK currently lacks support for abstractions like this, causing a compile error when trying to use
UserDefaultsClient
instead ofUserDefaults
:To work around this limitation, I am forced to add a new dependency endpoint that provides direct access to the wrapped
UserDefaults
instance.However, this workaround defeats the purpose of abstraction, as it forces us back to using a concrete
UserDefaults
instance.Solution
UserDefaultsProtocol
: Add a protocol to the SDK that mirrors theUserDefaults
methods used within the SDK:Extend
Configuration.Builder
: Add support forUserDefaultsProtocol
in theConfiguration.Builder
:Conform
UserDefaults
(andUserDefaultsClient
) toUserDefaultsProtocol
.The solution enables custom
UserDefaults
implementations, such asUserDefaultsClient
, to integrate seamlessly with the SDK, enhancing flexibility without introducing breaking changes to the public API.