Daniele B
08/12/2020, 11:33 AMrusshwolf
08/12/2020, 1:24 PMSharedPreferences
instance in your Android code, you can pass that to Settings
and have the same source of truth in your common code. If you don't care about that for your use-case, there is a multiplatform-settings-no-arg
module that adds a Settings()
function to instantiate a default-configured Settings
without needing to pass dependencies.
You could also use any other way you might pass a Context
around in a normal Android project. For example, that might be a dependency graph from Koin or Dagger or something similar, a manually configured Repository or DependencyManaager class that you construct from platform code, a ContentProvider that you use to store an Application context at app start (or the new androidx.startup
which helps automate this), or something else.Daniele B
08/12/2020, 2:51 PMmultiplatform-settings-no-arg
sounds awesome. But is there any reason why you don’t provide a constructor to specify the name of the SharedPreferences/NSUserDefaults ?russhwolf
08/12/2020, 2:52 PMDaniele B
08/12/2020, 2:52 PMDaniele B
08/12/2020, 2:52 PMDaniele B
08/12/2020, 2:52 PMrusshwolf
08/12/2020, 2:53 PMrusshwolf
08/12/2020, 2:55 PMDaniele B
08/12/2020, 2:56 PMDaniele B
08/12/2020, 2:57 PMmultiplatform-settings-no-arg
is awesome to allow you not to pass the ContextDaniele B
08/12/2020, 2:57 PMDaniele B
08/12/2020, 2:58 PMDaniele B
08/12/2020, 2:58 PMDaniele B
08/12/2020, 3:11 PMDaniele B
08/12/2020, 3:17 PMimplementation("com.russhwolf:multiplatform-settings-no-arg:0.6")
in CommonMain,
but I get an error when I try to use SettingsDaniele B
08/12/2020, 3:17 PMrusshwolf
08/12/2020, 3:29 PMcom.russhwolf.settings.Settings.Companion.invoke
russhwolf
08/12/2020, 3:30 PMDaniele B
08/12/2020, 3:32 PMDaniele B
08/12/2020, 3:32 PMrusshwolf
08/12/2020, 3:32 PMDaniele B
08/12/2020, 3:36 PMDaniele B
08/12/2020, 3:36 PMrusshwolf
08/12/2020, 3:39 PM./gradlew build
work from the command line?Daniele B
08/12/2020, 3:42 PMDaniele B
08/12/2020, 3:42 PM> Task :common:compileDebugKotlinAndroid FAILED
e: /myapp/common/repository/Repository.kt: (16, 38): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlin
russhwolf
08/12/2020, 3:44 PMDaniele B
08/12/2020, 3:45 PMDaniele B
08/12/2020, 3:54 PM