Closed dbaroncelli closed 4 years ago
Delegate APIs already exist. They're implemented as extension functions on Settings
, so the library doesn't care about any sort of SettingsClient
structure. You can place them wherever makes sense for your application.
val settings: Settings = ...
val a: Int by settings.int("a")
val b: Int by settings.int()
val c: Int? by settings.nullableInt()
OK, cool! I wasn't aware
I think I found a clean way to define and access the values, removing a lot of boilerplate code, by using Delegated Properties. In this way, there is no need to specify the key, as it's derived from the property name.
The values can be easily defined in this way, inside an object that implements a base class:
The base class holds an instance of the MultiplatformSettings, and defines a delegate for each type of values.
You might consider of providing a class like
SettingsClient
in the library, so that people can use the MultiplatformSettings in this very simple way.