Why a Settings Abstraction
One API over SharedPreferences and NSUserDefaults.
Why a Settings Abstraction is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Storage Gap
Android and iOS each ship their own way to save small values. Without a shared layer, you would write that code twice. Let's fix that. 🔑
Two Native Stores
Android stores small key-value data in SharedPreferences, while iOS uses NSUserDefaults. Same idea, two very different APIs.
One API to Rule Them
A Settings abstraction wraps both native stores behind a single Kotlin interface, so your shared code calls one method everywhere.
Meet Multiplatform Settings
The community library multiplatform-settings gives you exactly that: one Settings type backed by the right native store on each platform.
Add the Dependency
You add the multiplatform-settings artifact to your shared module's commonMain so every target can use it.
commonMain.dependencies {
implementation("com.russhwolf:multiplatform-settings:1.1.1")
}The Settings Interface
At its core sits the Settings interface. Your shared code depends on this type, never on the platform store directly.
interface Settings {
fun putString(key: String, value: String)
fun getString(key: String, defaultValue: String): String
}Why Abstract at All
Abstraction keeps your shared logic portable. Swap the backing store or add a platform later, and the calling code never changes.
Perfect for Small Data
Settings is built for small values: flags, a username, a theme choice. For big or relational data, reach for SQLDelight instead.
Inject, Don't Create
Each platform builds its own Settings instance and passes it into shared code, so commonMain stays free of platform dependencies.
Call It from Common
Once injected, your shared code just calls Settings methods. The same line runs on Android and iOS without a single change.
fun saveTheme(settings: Settings, theme: String) {
settings.putString("theme", theme)
}Test-Friendly by Design
Because it's an interface, you can drop in a fake in-memory Settings during tests, no device or emulator needed. 🧪
Quick Check
Let's make sure the abstraction's purpose is clear.
Recap
You learned why KMP wraps native key-value stores behind one Settings interface: portable, testable, and written once. Next, real reads and writes. 🎉
Frequently asked questions
Is the “Why a Settings Abstraction” lesson free?
Yes — the full text of “Why a Settings Abstraction” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.
What will I learn in “Why a Settings Abstraction”?
One API over SharedPreferences and NSUserDefaults. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Kotlin Multiplatform Academy?
No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Why a Settings Abstraction” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Kotlin Multiplatform Academy lesson?
Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why a Settings Abstraction
- Read & Write Typed Values
- Defaults & Clearing Keys
- Store an Auth Token Securely