Skip to content

gal-digital-gmbh/kmm-preferences

Repository files navigation

Download Kotlin badge badge

kotlin-multiplatform-mobile

SharedPreference in Kotlin Multiplatform Mobile (KMM)

This is a Kotlin MultiPlatform library that provides access to the shared preferences on iOS & Android.

setup

kotlin {
  sourceSets {
    val commonMain by getting {
      dependencies {
        implementation("de.gal-digital:kmm-preferences:x.x.x")
      }
    }
  }
}

usage

class Settings(sharedPreferences : SharedPreferences) {

  private val jsonSerializer = Json {}

  var token : String? by preference(sharedPreferences, "token", null)

  var user : SomeSerializable? by serializable(sharedPreferences,jsonSerializer,"user", null)
}