Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/florent37/Multiplatform-Preferences
Kotlin Multi Platform Preferences, for android an ios : SharedPreferences & NSUserDefault
https://github.com/florent37/Multiplatform-Preferences
android default ios java kotlin multiplatform native nsuserdefaults preferences session sharedpreferences
Last synced: about 20 hours ago
JSON representation
Kotlin Multi Platform Preferences, for android an ios : SharedPreferences & NSUserDefault
- Host: GitHub
- URL: https://github.com/florent37/Multiplatform-Preferences
- Owner: florent37
- License: apache-2.0
- Archived: true
- Created: 2018-11-04T19:49:12.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-18T12:50:58.000Z (over 4 years ago)
- Last Synced: 2024-08-02T09:26:28.814Z (3 months ago)
- Topics: android, default, ios, java, kotlin, multiplatform, native, nsuserdefaults, preferences, session, sharedpreferences
- Language: Kotlin
- Size: 23.9 MB
- Stars: 86
- Watchers: 4
- Forks: 10
- Open Issues: 4
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-multiplatform - Multiplatform-Preferences - Kotlin Multi Platform Preferences, for android an ios : SharedPreferences & NSUserDefault. (Libraries / Storage)
README
# Multiplatform Preferences
Use a single object : `Preferences` in your kotlin shared projects
Compatible with kotlin android and kotlin native for iphone
```kotlin
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
```groovy
repositories {
maven { url "https://dl.bintray.com/florent37/maven" }
}
```## common
```groovy
implementation "com.github.florent37:multiplatform-preferences:1.2.0"
```## ios
Uses inside the NSUserDefaults
```groovy
implementation "com.github.florent37:multiplatform-preferences-ios:1.2.0"
```## android
Uses inside the SharedPreferences
```groovy
implementation "com.github.florent37:multiplatform-preferences-android:1.2.0"
```## Methods
```kotlin
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.