
Lightweight, simple unified API to persist primitive values via native preference systems, supports custom preference names and requires minimal setup.
Save primitive values effortlessly across Android & iOS! One simple, unified API for SharedPreferences (Android) and UserDefaults (iOS). Lightweight Kotlin Multiplatform library – write once, persist anywhere. 🚀
Make sure you have Maven Central in your repositories:
repositories {
mavenCentral()
// other repositories if needed
}Add the dependency in your commonMain source set:
implementation("io.github.shahzaibali02:kmpsharedpref:1.0.3")Before using the library on Android, initialize it with a context (usually in your Application class):
KMPSharedPref.init(context)val sharedPref = createSharedPref("MyCustomPrefName")sharedPref.saveString("username", "Shahzaib")
sharedPref.saveInt("age", 25)
sharedPref.saveBool("isPremium", true)
sharedPref.saveLong("salary", 1123123123121)
sharedPref.saveFloat("height", 5.9f)val name = sharedPref.getString("username")
val age = sharedPref.getInt("age")
val isPremium = sharedPref.getBool("isPremium")
val salary = sharedPref.getLong("salary")
val height = sharedPref.getFloat("height")fun saveString(key: String, value: String)
fun saveInt(key: String, value: Int)
fun saveLong(key: String, value: Long)
fun saveBool(key: String, value: Boolean)
fun saveFloat(key: String, value: Float)
fun getString(key: String, defaultValue: String = ""): String
fun getInt(key: String, defaultValue: Int = 0): Int
fun getLong(key: String, defaultValue: Long = 0L): Long
fun getBool(key: String, defaultValue: Boolean = false): Boolean
fun getFloat(key: String, defaultValue: Float = 0.0f): FloatThis library is open source under the MIT License.
Save primitive values effortlessly across Android & iOS! One simple, unified API for SharedPreferences (Android) and UserDefaults (iOS). Lightweight Kotlin Multiplatform library – write once, persist anywhere. 🚀
Make sure you have Maven Central in your repositories:
repositories {
mavenCentral()
// other repositories if needed
}Add the dependency in your commonMain source set:
implementation("io.github.shahzaibali02:kmpsharedpref:1.0.3")Before using the library on Android, initialize it with a context (usually in your Application class):
KMPSharedPref.init(context)val sharedPref = createSharedPref("MyCustomPrefName")sharedPref.saveString("username", "Shahzaib")
sharedPref.saveInt("age", 25)
sharedPref.saveBool("isPremium", true)
sharedPref.saveLong("salary", 1123123123121)
sharedPref.saveFloat("height", 5.9f)val name = sharedPref.getString("username")
val age = sharedPref.getInt("age")
val isPremium = sharedPref.getBool("isPremium")
val salary = sharedPref.getLong("salary")
val height = sharedPref.getFloat("height")fun saveString(key: String, value: String)
fun saveInt(key: String, value: Int)
fun saveLong(key: String, value: Long)
fun saveBool(key: String, value: Boolean)
fun saveFloat(key: String, value: Float)
fun getString(key: String, defaultValue: String = ""): String
fun getInt(key: String, defaultValue: Int = 0): Int
fun getLong(key: String, defaultValue: Long = 0L): Long
fun getBool(key: String, defaultValue: Boolean = false): Boolean
fun getFloat(key: String, defaultValue: Float = 0.0f): FloatThis library is open source under the MIT License.