### Android SharedPreferencesSettings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Provides an example of creating a Settings instance on Android by wrapping SharedPreferences. ```kotlin val delegate: SharedPreferences // ... val settings: Settings = SharedPreferencesSettings(delegate) ``` -------------------------------- ### Delegate API for Serializable Objects Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This example showcases the delegate API for working with serializable objects in the multiplatform-settings library. It simplifies property access by allowing direct delegation for both non-nullable and nullable serializable values. ```kotlin val someClass: SomeClass by settings.serializedValue(SomeClass.serializer(), "someClass", defaultValue) val nullableSomeClass: SomeClass? by settings.nullableSerializedValue(SomeClass.serializer(), "someClass") ``` -------------------------------- ### Settings API: Storing Values Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates how to store integer values in the `Settings` instance using both explicit `putXXX()` methods and convenient operator shortcuts. The example shows setting an integer value and its equivalent using the `[]` operator. ```kotlin settings.putInt("key", 3) settings["key"] = 3 ``` -------------------------------- ### Storing and Retrieving Serializable Objects with Settings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This example illustrates how to store and retrieve custom serializable objects using the `Settings` interface and the serialization module. It covers encoding and decoding values, handling nullable values, and removing serialized data. ```kotlin @Serializable class SomeClass(val someProperty: String, anotherProperty: Int) val someClass: SomeClass val settings: Settings // Store values for the properties of someClass in settings settings.encodeValue(SomeClass.serializer(), "key", someClass) // Create a new instance of SomeClass based on the data in settings val newInstance: SomeClass = settings.decodeValue(SomeClass.serializer(), "key", defaultValue) val nullableNewInstance: SomeClass = settings.decodeValueOrNull(SomeClass.serializer(), "key") ``` -------------------------------- ### Add No-Arg Multiplatform Settings Dependency Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This snippet shows how to add the `multiplatform-settings-no-arg` Gradle dependency to your project for simplified setup. This dependency exports `multiplatform-settings` as an API dependency, allowing for direct instantiation of `Settings` without platform-specific arguments. ```kotlin implementation("com.russhwolf:multiplatform-settings-no-arg:1.3.0") ``` -------------------------------- ### ObservableSettings Flow Extensions Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Provides Flow extensions for `ObservableSettings` to get settings values as Flows. These extensions internally use the listener APIs. ```kotlin val observableSettings: ObservableSettings // Only works with ObservableSettings val flow: Flow by observableSettings.getIntFlow("key", defaultValue) val nullableFlow: Flow by observableSettings.getIntOrNullFlow("key") ``` -------------------------------- ### Settings API: Retrieving Nullable Values Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates retrieving values that might be absent from `Settings` without needing a default value. It shows how to use `getXXXOrNull()` methods and the nullable operator shortcut `[]` to get a nullable type, returning `null` if the key is not found. ```kotlin val a: Int? = settings.getIntOrNull("key") val b: Int? = settings["key"] ``` -------------------------------- ### Windows RegistrySettings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates creating a Settings instance on Windows by wrapping the Windows registry. ```kotlin val rootKey: String = "SOFTWARE\..." // Will be interpreted as subkey of HKEY_CURRENT_USER val settings: Settings = RegistrySettings(rootKey) ``` -------------------------------- ### DataStoreSettings Implementation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates how to create a `FlowSettings` instance using `DataStoreSettings` with a Jetpack DataStore object. ```kotlin val dataStore: DataStore // = ... val settings: FlowSettings = DataStoreSettings(dataStore) ``` -------------------------------- ### Creating Settings Instance with Expect Declarations Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates how to declare a Settings instance using 'expect' for multiplatform compatibility, allowing platform-specific implementations to provide the actual Settings object. ```kotlin expect val settings: Settings // or expect fun createSettings(): Settings ``` -------------------------------- ### JVM PreferencesSettings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates creating a Settings instance on the JVM by wrapping the Preferences API. ```kotlin val delegate: Preferences // ... val settings: Settings = PreferencesSettings(delegate) ``` -------------------------------- ### Default Settings Factory Instantiation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to instantiate a Settings Factory on most other platforms without requiring any parameters. ```kotlin val factory: Settings.Factory = NSUserDefaultsSettings.Factory() ``` -------------------------------- ### Settings Implementations Summary Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This table summarizes the available `Settings` implementations, their backing APIs, and the platforms they support. Some implementations offer experimental features or different interfaces like `ObservableSettings` or `SuspendSettings`. ```APIDOC Class Name: KeychainSettings Backing API: Apple Keychain Platforms: iOS, macOS, watchOS, tvOS Notes: Experimental implementation. Class Name: NSUserDefaultsSettings Backing API: User Defaults Platforms: iOS, macOS, watchOS, tvOS Notes: Implements ObservableSettings interface. Class Name: PreferencesSettings Backing API: java.util.prefs.Preferences Platforms: JVM Notes: Implements ObservableSettings interface. Class Name: PropertiesSettings Backing API: java.util.Properties Platforms: JVM Class Name: SharedPreferencesSettings Backing API: android.content.SharedPreferences Platforms: Android Notes: Implements ObservableSettings interface. Class Name: StorageSettings Backing API: Web Storage (localStorage) Platforms: JS, WasmJS Class Name: RegistrySettings Backing API: Windows Registry Platforms: MingwX64 Notes: Experimental implementation. Class Name: DataStoreSettings Backing API: androidx.datastore.core.DataStore Platforms: Android, JVM, Native Notes: Implements SuspendSettings and FlowSettings. Class Name: MapSettings Backing API: kotlin.collections.MutableMap Platforms: All platforms Notes: Intended for unit tests; does not persist data. ``` -------------------------------- ### Manual Deployment Script Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This describes the `deploy.yml` script, which is triggered manually. It builds the library for all supported platforms and uploads the artifacts to staging on Maven Central. Manual publication of uploaded artifacts is still required. ```yaml deploy.yml ``` -------------------------------- ### JVM PropertiesSettings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates creating a Settings instance on the JVM by wrapping the Properties API. ```kotlin val delegate: Properties // ... val settings: Settings = PropertiesSettings(delegate) ``` -------------------------------- ### Creating Settings Instance in Pure Common Code Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates the simplified way to create a Settings instance directly in common code using the no-arg Settings() factory function. ```kotlin val settings: Settings = Settings() ``` -------------------------------- ### Instantiate Settings with No-Arg Module Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates how to create a `Settings` instance from common code using the no-arg module. This leverages a top-level function `Settings()` which internally handles platform-specific implementations like `NSUserDefaults` on Apple platforms, `localStorage` on JS, and `Preferences` on JVM. ```kotlin val settings: Settings = Settings() ``` -------------------------------- ### iOS/macOS/tvOS/watchOS NSUserDefaultsSettings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates creating a Settings instance for Apple platforms by wrapping NSUserDefaults. ```kotlin val delegate: NSUserDefaults // ... val settings: Settings = NSUserDefaultsSettings(delegate) ``` -------------------------------- ### JS/WasmJS StorageSettings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to create a Settings instance for JavaScript and WasmJS environments, wrapping the browser's Storage API. ```kotlin val delegate: Storage // ... val settings: Settings = StorageSettings(delegate) val settings: Settings = StorageSettings() // use localStorage by default ``` -------------------------------- ### Settings API Overview Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Provides a high-level overview of the `Settings` API, detailing methods for storing, retrieving, and managing key-value data across different platforms. It covers basic operations, default values, nullable types, property delegation, key management, and listeners. ```APIDOC Settings API: Storing Values: putInt(key: String, value: Int) operator fun set(key: String, value: Int) Retrieving Values: getInt(key: String): Int getInt(key: String, defaultValue: Int): Int operator fun get(key: String): Int operator fun get(key: String, defaultValue: Int): Int Nullable Values: getIntOrNull(key: String): Int? operator fun get(key: String): Int? Property Delegation: int(key: String, defaultValue: Int = ...): ReadWriteProperty nullableInt(key: String): ReadWriteProperty int(): ReadWriteProperty // Uses property name as key Key Management: hasKey(key: String): Boolean operator fun contains(key: String): Boolean remove(key: String) operator fun minusAssign(key: String) operator fun set(key: String, value: Nothing?) clear() keys: Set size: Int Listeners (ObservableSettings): addIntListener(key: String, listener: (Int) -> Unit): SettingsListener addNullableIntListener(key: String, listener: (Int?) -> Unit): SettingsListener SettingsListener.deactivate() ``` -------------------------------- ### Project Dependencies Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Instructions for adding the Multiplatform Settings library to your project by including Maven Central in repositories and adding the dependency to your common source-set. ```kotlin repositories { mavenCentral() // ... } commonMain { dependencies { // ... implementation("com.russhwolf:multiplatform-settings:1.3.0") } } ``` -------------------------------- ### KeychainSettings for Secure Storage Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to create a Settings instance that securely stores data in the Keychain on Apple platforms, using a service name. ```kotlin val serviceName: String // ... val settings: Settings = KeychainSettings(serviceName) ``` -------------------------------- ### Using Settings Factory in Common Code Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to use a Factory object, injected from platform code, to create multiple named Settings instances from common code. ```kotlin val settings1: Settings = factory.create("my_first_settings") val settings2: Settings = factory.create("my_other_settings") ``` -------------------------------- ### Platform-Specific FlowSettings Implementation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to provide a platform-specific implementation of `FlowSettings`, using `DataStoreSettings` on Android and `NSUserDefaultsSettings` on iOS. ```kotlin // Common expect val settings: FlowSettings // Android actual val settings: FlowSettings = DataStoreSettings(/*...*/) // iOS actual val settings: FlowSettings = NSUserDefaultsSettings(/*...*/).toFlowSettings() ``` -------------------------------- ### Settings API: Retrieving Values Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to retrieve integer values from `Settings`, including handling cases where a key might not be present by providing a default value. It demonstrates using `getXXX()` methods and operator shortcuts with and without default values. ```kotlin val a: Int = settings.getInt("key") val b: Int = settings.getInt("key", defaultValue = -1) val c: Int = settings["key", -1] ``` -------------------------------- ### Github Actions CI Jobs Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This section details the CI jobs configured using Github Actions for the multiplatform-settings project. It covers builds for Linux, macOS, and Windows, including validation of the Gradle wrapper and deployment of build artifacts to the local Maven repository. The sample project is also built for supported platforms to ensure synchronization with library updates. ```yaml build-linux.yml build-macos.yml build-windows.yml validate-gradle-wrapper.yml ``` -------------------------------- ### DataStore Settings Dependency Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Integrates Jetpack DataStore as a `FlowSettings` implementation. This module is available on all platforms where DataStore is supported. ```kotlin implementation("com.russhwolf:multiplatform-settings-datastore:1.3.0") ``` -------------------------------- ### Apache License 2.0 Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This is the full text of the Apache License, Version 2.0, which governs the use of the multiplatform-settings project. It outlines the permissions and limitations for using the software, including the requirement to retain copyright and license notices. ```text Copyright 2018-2023 Russell Wolf 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. ``` -------------------------------- ### Make-Observable Module Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Adds an experimental `makeObservable()` extension to `Settings` to convert it to `ObservableSettings` by directly wiring callbacks. This enables observability on platforms without native support. ```kotlin val settings: Settings // = ... val observableSettings: ObservableSettings = settings.makeObservable() ``` -------------------------------- ### Testing Dependency for Multiplatform Settings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This snippet shows how to include the testing dependency for the multiplatform-settings library. It provides a `MapSettings` implementation backed by an in-memory map, useful for testing code that interacts with the `Settings` interface across different platforms. ```kotlin implementation("com.russhwolf:multiplatform-settings-test:1.3.0") ``` -------------------------------- ### Settings API: Nullable Property Delegation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates nullable property delegates for `Settings`, allowing the absence of a key to be represented by `null`. This simplifies handling optional values by directly binding them to nullable properties. ```kotlin val a: Int? by settings.nullableInt("key") ``` -------------------------------- ### Settings API: Retrieving Keys and Size Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates how to retrieve the set of all keys currently stored in `Settings` and the total number of entries. The `keys` property returns a `Set`, and the `size` property returns an `Int`. ```kotlin val keys: Set = settings.keys val size: Int = settings.size ``` -------------------------------- ### Settings API: Key Existence Check Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates methods for checking if a key exists within the `Settings` instance. It shows the `hasKey()` method and the `in` operator for boolean checks on key presence. ```kotlin val a: Boolean = settings.hasKey("key") val b: Boolean = "key" in settings ``` -------------------------------- ### Settings API: Property Delegation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Explains how to use property delegates with `Settings` to ensure consistent type access for keys. It shows standard delegates for typed values and delegates with default values, ensuring the key is always accessed with the correct type. ```kotlin val a: Int by settings.int("key") val b: Int by settings.int("key", defaultValue = -1) ``` -------------------------------- ### Serialization Module for Multiplatform Settings Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This snippet demonstrates how to integrate the `kotlinx-serialization` module with the multiplatform-settings library. This integration simplifies saving and retrieving non-primitive data types by using the `Settings` store as a serialization format. ```kotlin implementation("com.russhwolf:multiplatform-settings-serialization:1.3.0") ``` -------------------------------- ### Android SharedPreferencesSettings Factory Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates creating a SharedPreferencesSettings Factory on Android, which requires a Context parameter. ```kotlin val context: Context // ... val factory: Settings.Factory = SharedPreferencesSettings.Factory(context) ``` -------------------------------- ### SuspendSettings and FlowSettings Interfaces Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Introduces `SuspendSettings` for suspendable operations and `FlowSettings` for Flow-based getters, offering a more modern coroutine-friendly API. ```kotlin val suspendSettings: SuspendSettings // ... val a: Int = suspendSettings.getInt("key") // This call will suspend val flowSettings: FlowSettings // ... val flow: Flow = flowSettings.getIntFlow("key") ``` -------------------------------- ### Settings API: Reflective Property Delegation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows how to use property delegates where the key parameter can be omitted. In such cases, the property name is used reflectively as the key for accessing `Settings`, simplifying code when property names match desired keys. ```kotlin val a: Int by settings.int() // internally, key is "a" ``` -------------------------------- ### Platform-Specific SuspendSettings Implementation Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Illustrates providing platform-specific `SuspendSettings`, including `DataStoreSettings` for Android, `NSUserDefaultsSettings` for iOS, and `StorageSettings` for JS. ```kotlin // Common expect val settings: SuspendSettings // Android actual val settings: SuspendSettings = DataStoreSettings(/*...*/) // iOS actual val settings: SuspendSettings = NSUserDefaultsSettings(/*...*/).toSuspendSettings() // JS actual val settings: SuspendSettings = StorageSettings().toSuspendSettings() ``` -------------------------------- ### Settings Interface Conversions Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Provides utility functions to convert between different `Settings` interfaces (`Settings`, `SuspendSettings`, `FlowSettings`, `ObservableSettings`), allowing for flexible API usage. ```kotlin val settings: Settings // ... val suspendSettings: SuspendSettings = settings.toSuspendSettings() val observableSettings: ObservableSettings // ... val flowSettings: FlowSettings = observableSettings.toFlowSettings() // Wrap suspend calls in runBlocking val blockingSettings: Settings = suspendSettings.toBlockingSettings() val blockingSettings: ObservableSettings = flowSettings.toBlockingObservableSettings() ``` -------------------------------- ### ObservableSettings API: Adding Listeners Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates how to add update listeners to `ObservableSettings` implementations. It shows adding listeners for integer values, including nullable integers, and the type of listener object returned. ```kotlin val observableSettings: ObservableSettings // ... val settingsListener: SettingsListener = observableSettings.addIntListener(key) { value: Int -> /* ... */ } val settingsListener: SettingsListener = observableSettings.addNullableIntListener(key) { value: Int? -> /* ... */ } ``` -------------------------------- ### Implicit Serializer Usage Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This code illustrates the use of `Settings` APIs that implicitly infer the serializer. These methods are convenient but will throw an exception if the class is not serializable. This applies to encoding, decoding, and other related operations. ```kotlin settings.encodeValue("key", someClass) val newInstance: SomeClass = settings.decodeValue("key", defaultValue) val nullableNewInstance: SomeClass = settings.decodeValueOrNull("key") ``` -------------------------------- ### ObservableSettings StateFlow Extensions Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Provides StateFlow extensions for `ObservableSettings`, requiring a CoroutineScope. These extensions allow settings to be observed as StateFlows. ```kotlin val observableSettings: ObservableSettings // Only works with ObservableSettings val coroutineScope: CoroutineScope val stateFlow: StateFlow by observableSettings.getIntStateFlow("key", defaultValue) val nullableStateFlow: StateFlow by observableSettings.getIntOrNullStateFlow("key") ``` -------------------------------- ### Coroutine Dependency Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Adds flow extensions for all types which use the listener APIs internally. Requires the `multiplatform-settings-coroutines` dependency. ```kotlin implementation("com.russhwolf:multiplatform-settings-coroutines:1.3.0") ``` -------------------------------- ### Settings API: Removing Values Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Demonstrates various ways to remove values from `Settings` by key. This includes the `remove()` method, the `-=` operator, and setting a value to `null` using the `[]` operator. ```kotlin settings.remove("key") settings -= "key" settings["key"] = null ``` -------------------------------- ### Settings API: Clearing All Values Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Shows the `clear()` method for removing all values from the `Settings` instance. It notes that for certain implementations like `NSUserDefaultsSettings`, some entries might remain unremovable and persist after a `clear()` operation. ```kotlin settings.clear() ``` -------------------------------- ### Removing and Checking for Serialized Values Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md This code demonstrates how to remove serialized values and check for their existence using the `Settings` interface. It highlights the use of `removeValue()` and `containsValue()` for managing serialized data, including an option to ignore partial data during removal. ```kotlin settings.removeValue(SomeClass.serializer(), "key") // Don't remove if not all expected data is preset settings.removeValue(SomeClass.serializer(), "key", ignorePartial = true) val isPresent = settings.containsValue(SomeClass.serializer(), "key") ``` -------------------------------- ### ObservableSettings API: Deactivating Listeners Source: https://github.com/russhwolf/multiplatform-settings/blob/main/README.md Explains how to deactivate an added listener using the `deactivate()` method on the returned `SettingsListener` object. It also notes the importance of holding a strong reference to the listener to ensure continuous updates. ```kotlin settingsListener.deactivate() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.