Kotlin Multiplatform, from the compiler up · check

Know Living on iOS, and sharing the UI already?

One question for each of the 5 puzzles in this module. A right answer marks that puzzle as passed, so you can jump ahead. A wrong one tells you which puzzle to start with. Nothing is sent anywhere: it's saved in this browser.

Puzzle 5: Two ways to free memory

Kotlin holds a Swift object, then lets go. When does Swift's deinit run?

Right. Release follows Kotlin's GC, not the moment of letting go.

Not quite. It's freed, only later: at the next garbage collection. Learn it in puzzle 5 →

Not quite. Kotlin's hold is released by the collector, so the Swift object waits for the next GC. Learn it in puzzle 5 →

Puzzle 6: Whose thread is it?

Your shared code resumes a coroutine on Dispatchers.Main on iOS. Which thread runs it?

Right. Main is still the main thread on iOS.

Not quite. The dispatcher decides, not the caller: Main means the main queue. Learn it in puzzle 6 →

Not quite. On iOS, Main is backed by the main queue, so it still runs on the main thread. Learn it in puzzle 6 →

Puzzle 7: One framework, not two

An app imports two Kotlin frameworks, and both contain the same User class. Swift passes a User from one to the other. What happens?

Not quite. Each framework has its own runtime and its own copy of the class; to Swift they're different types. Learn it in puzzle 7 →

Right. Two frameworks, two copies of every type.

Not quite. Where the class came from doesn't help: two frameworks, two types. Learn it in puzzle 7 →

Puzzle 8: What Compose actually shares

Your app targets Android and iOS with Compose Multiplatform. Which build of material3 does the Android app use?

Right. Android gets Google's artifacts.

Not quite. material3 is available from common code on all targets. Learn it in puzzle 8 →

Not quite. On Android the build switches to Google's artifacts; JetBrains' builds are for the other targets. Learn it in puzzle 8 →

Puzzle 9: One canvas on iOS

Your Compose screen on iOS has a Column with a Button. What does UIKit see?

Right. One view, drawn by Compose.

Not quite. UIKit still runs the app; Compose lives inside one of its screens. Learn it in puzzle 9 →

Not quite. Compose doesn't create UIKit objects for composables; it draws them itself. Learn it in puzzle 9 →

Back to the overview →