Coder Social home page Coder Social logo

matsawa / userpreferences Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 0.0 107 KB

Kotlin Multiplatform library for storing key-value data in Android and iOS applications

License: MIT License

Kotlin 96.90% Swift 3.10%
android ios key-value kotlin kotlin-multiplatform settings sharedpreferences userdefaults

userpreferences's Introduction

User Preferences

Kotlin Multiplatform Key-Value Storage Library

This is a Kotlin Multiplatform library for storing key-value data in Android and iOS applications. It is designed to provide a consistent interface for storing and retrieving data across both platforms. Under the hood, the library uses Shared Preferences on Android and User Defaults on iOS.

Requirements

Android API Level >= 21 iOS ios_arm64 and ios_x64 targets

Adding the library to your project

To use the library, you need to add the library to your project dependencies. Here's how you can do it in Gradle:

Add mavenCentral to your repositories in the build.gradle.kts file:

repositories {
    mavenCentral()
    // others
}

Add the library to your project dependencies in the commonMain:

 commonMain {
    dependencies {
        implementation("com.matsawa:userpreferences:0.0.1")
        // others
    }
}

Adding the library to your project

After adding the library, you can use it in your code. Here is an example of how to store and retrieve a String value:

// Store a value
userPreferences.addString("myKey", "myValue")

// Retrieve a value
val value = userPreferences.getString("myKey")

The library also supports other basic data types, such as Boolean, Int, Long, Float, and Double:

// Store a value
userPreferences.addBoolean("myKey", true)

// Retrieve a value
val value = userPreferences.getBoolean("myKey")

You can also retrieve any data type with a default value if the key is not found in storage:

// Retrieve a value with a default if not found
val value = userPreferences.getInt("myKey", defaultValue = value)

You can remove a single element by key:

// Remove a single element by key
userPreferences.remove("myKey")

You can remove all elements:

// Remove all elements
userPreferences.clear()

You can check if an element exists:

// Check if an element exists
val exists = userPreferences.contains("myKey")

For more information on how to use the library, please check our sample.

Contributing

Contributions to the library are welcome. If you find a bug or have a feature request, please open an issue on the GitHub repository. If you would like to contribute code, please fork the repository and submit a pull request.

License

The library is released under the MIT License. Please see the LICENSE file for more information.

userpreferences's People

Contributors

matsawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.