0Pricing
Kotlin Multiplatform Academy · Lesson

Read & Write Typed Values

Persist booleans, strings and ints safely.

Read & Write Typed Values is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 2 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.

Typed, Not Stringly

Settings stores more than strings. It has dedicated methods for each basic type, so you keep your data typed and safe. 🧩

Write a String

Use putString to save text under a key. The key is just a label you'll use to read it back later.

settings.putString("username", "ada")

Read a String

Read it back with getString, passing a fallback for when the key was never written.

val name = settings.getString("username", "guest")

Booleans for Flags

Toggle features with putBoolean and getBoolean. Perfect for things like a dark-mode switch or onboarding-seen flag.

settings.putBoolean("darkMode", true)
val dark = settings.getBoolean("darkMode", false)

Numbers Too

Store counters and ids with putInt and putLong. Each numeric type has its own matching getter.

settings.putInt("launchCount", 5)
val count = settings.getInt("launchCount", 0)

Floats and Doubles

Need decimals? Use putFloat or putDouble to persist values like a saved volume level or a cached price.

settings.putDouble("volume", 0.75)
val vol = settings.getDouble("volume", 1.0)

Keys Are Just Strings

Every value lives under a string key. Pick stable, descriptive names and reuse the exact same key to read and write.

Centralize Your Keys

Typos in keys cause silent bugs. Define keys as constants in one place so reads and writes always agree.

object Keys {
    const val USERNAME = "username"
    const val DARK_MODE = "darkMode"
}

The Operator Shortcut

multiplatform-settings adds operator overloads so you can index into settings almost like a map.

settings["username"] = "grace"
val name: String? = settings["username"]

Same Code, Both Apps

These typed calls live in commonMain. Android and iOS run the identical lines, each hitting its own native store underneath.

Match the Types

Always read with the same type you wrote. Writing an Int then reading it as a String won't return what you expect.

Quick Check

Let's check how typed access works.

Recap

You can now read and write strings, booleans, ints, and decimals with matching typed methods, keyed by stable constants. Next: defaults and clearing. 🎉

Frequently asked questions

Is the “Read & Write Typed Values” lesson free?

Yes — the full text of “Read & Write Typed Values” 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 “Read & Write Typed Values”?

Persist booleans, strings and ints safely. 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 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Read & Write Typed Values” 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

  1. Why a Settings Abstraction
  2. Read & Write Typed Values
  3. Defaults & Clearing Keys
  4. Store an Auth Token Securely
← Back to Kotlin Multiplatform Academy