native-defaults

KMM implementation of user's preferences storage API

License

License

Categories

Categories

Native Development Tools
GroupId

GroupId

com.github.grigorevp
ArtifactId

ArtifactId

native-defaults
Last Version

Last Version

1.0.5
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

native-defaults
KMM implementation of user's preferences storage API
Project URL

Project URL

https://github.com/grigorevp/native-defaults
Source Code Management

Source Code Management

https://github.com/grigorevp/native-defaults

Download native-defaults

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.30

Project Modules

There are no modules declared in this project.

Maven Central Kotlin

native-defaults

Overview

A simple KMM implementation of user's preferences storage API, using SharedPreferences for Android and UserDefaults for iOS.

Add dependency

Specify a dependency in your commonMain part to add native-defaults to your project:

implementation("com.github.grigorevp:native-defaults:${latestVersion}")

Don't forget to include mavenCentral() in repository list if it's not already there.

Use in common module

To start working with native-defaults one should firstly initialize an instance. You can either use standard initializer to store defaults in a standard domain (persistence) or specify a name, to create isolated domains:

//This will create an instance holding standard domain
val defaults = NativeDefaults()

//This will create an instance for a domain with a specified name:
val myDefaults = NativeDefaults("MyRepo")

Please avoid specifying "Standard" domain name as it is reserved and will throw an error.

To add values to the perisitence domain use:

defaults.setString(key: String, value: String)

defaults.setInt(key: String, value: Int)

defaults.setFloat(key: String, value: Float)

defaults.setBoolean(key: String, value: Boolean)

defaults.setStringSet(key: String, value: Set<String>)

To get values use:

defaults.getString(key: String): String?

defaults.getInt(key: String): Int?

defaults.getFloat(key: String): Float?

defaults.getBoolean(key: String): Boolean?

defaults.getStringSet(key: String): Set<String>?

To clear a value for key use:

defaults.clearValue(key: String)

Versions

Version
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0