Coder Social home page Coder Social logo

florent37 / multiplatform-preferences Goto Github PK

View Code? Open in Web Editor NEW
86.0 4.0 10.0 24.48 MB

Kotlin Multi Platform Preferences, for android an ios : SharedPreferences & NSUserDefault

License: Apache License 2.0

Kotlin 98.93% Shell 1.07%
kotlin native android ios java multiplatform sharedpreferences nsuserdefaults session default

multiplatform-preferences's Introduction

Multiplatform Preferences

Use a single object : Preferences in your kotlin shared projects

Compatible with kotlin android and kotlin native for iphone

class MyPresenter {
    val preferences = Preferences()

    fun start(){
        preferences.getString("userName")?.let {
            view.displayUser(it)
        }
        
        val age = preferences.getInt("age", 18)
        view.displayUserAge(age)
    }
}

Download

Add the repository

repositories {
    maven { url "https://dl.bintray.com/florent37/maven" }
}

common

implementation "com.github.florent37:multiplatform-preferences:1.2.0"

ios

Uses inside the NSUserDefaults

implementation "com.github.florent37:multiplatform-preferences-ios:1.2.0"

android

Uses inside the SharedPreferences

implementation "com.github.florent37:multiplatform-preferences-android:1.2.0"

Methods

class Preferences(name: String? = null) {

    fun setInt(key: String, value: Int)
    fun getInt(key: String, defaultValue: Int): Int
    fun getInt(key: String): Int?

    fun setFloat(key: String, value: Float)
    fun getFloat(key: String, defaultValue: Float): Float
    fun getFloat(key: String): Float?

    fun setLong(key: String, value: Long)
    fun getLong(key: String, defaultValue: Long): Long
    fun getLong(key: String): Long?

    fun setString(key: String, value: String)
    fun getString(key: String, defaultValue: String): String
    fun getString(key: String): String?

    fun setBoolean(key: String, value: Boolean)
    fun getBoolean(key: String, defaultValue: Boolean): Boolean
    fun getBoolean(key: String): Boolean?

    fun remove(key: String)
    fun clear()

    fun hasKey(key: String): Boolean
}

License

Copyright 2018 Florent37

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

multiplatform-preferences's People

Contributors

florent37 avatar pecanw avatar russhwolf avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

multiplatform-preferences's Issues

readme typo

gitub->github

thx for lib btw, great stuff

Not compatible with Kotiln Multiplatform 1.3.61

When I try to sync v1.0.0 in Android Studio, I get this error:

Incompatible Kotlin/Native libraries
			There is a third-party library attached to the project that was compiled with an older Kotlin/Native compiler and can't be read in IDE: Gradle: com.github.florent37:multiplatform-preferences-ios_debug_ios_x64:klib:1.0.0
			Please edit Gradle buildfile(s) and specify library version compatible with Kotlin/Native 1.3.61. Then re-import the project in IDE.

It builds in Android, but when I try to build the iOS binary, I get this:

Task :app:compileKotlinIos FAILED
w: skipping /.gradle/caches/modules-2/files-2.1/com.github.florent37/multiplatform-preferences-ios_debug_ios_x64/1.0.0/78fa121f1fbe3f65693688cf7cf134d270c71fd4/multiplatform-preferences-ios.klib. The abi versions don't match. Expected '[17]', found '2'
w: The compiler versions don't match either. Expected '[]', found '1.0.1-release-4583'
e: Could not find "/.gradle/caches/modules-2/files-2.1/com.github.florent37/multiplatform-preferences-ios_debug_ios_x64/1.0.0/78fa121f1fbe3f65693688cf7cf134d270c71fd4/multiplatform-preferences-ios.klib" in [/app, /.konan/klib, /.konan/kotlin-native-macos-1.3.61/klib/common, /.konan/kotlin-native-macos-1.3.61/klib/platform/ios_x64].

FAILURE: Build failed with an exception.

Problem pom not found version 1.0.2

Could not find com.github.florent37:multiplatform-preferences-android:1.0.2.
Searched in the following locations:
  - https://dl.bintray.com/florent37/maven/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://dl.bintray.com/florent37/maven/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar
  - https://dl.bintray.com/suparnatural/kotlin-multiplatform/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://dl.bintray.com/suparnatural/kotlin-multiplatform/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar
  - https://maven.google.com/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://maven.google.com/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar
  - https://kotlin.bintray.com/kotlinx/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://kotlin.bintray.com/kotlinx/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar
  - https://dl.google.com/dl/android/maven2/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://dl.google.com/dl/android/maven2/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar
  - https://jcenter.bintray.com/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://jcenter.bintray.com/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar
  - https://repo.maven.apache.org/maven2/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.pom
  - https://repo.maven.apache.org/maven2/com/github/florent37/multiplatform-preferences-android/1.0.2/multiplatform-preferences-android-1.0.2.jar

It is worked?

Does this work for anyone on both platforms? And how did you achieve this?

Android:1.2.0 could not resolve dependency

I am getting the following error:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.florent37:multiplatform-preferences-android:1.2.0.

I have tested version 1.0.0 and it compiles without any problem. Common and iOS resolved correctly.

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.