An ID in shared code
An expect/actual exercise
In a module targeting Android and iOS, commonMain cannot import java.util.UUID. Practice the platform boundary by keeping Note in commonMain and implementing expect fun randomId(): String with Android and iOS actual declarations.
Contract: a lowercase UUID string in standard hyphenated form. Compute it once when a Note is created; reading the same Note again must not generate a new ID. Random generation does not promise mathematical impossibility of a collision.
Split the solution into commonMain/androidMain/iosMain files in the same package. Check both builds, string format and the stability of a single Note's ID. The editor represents several files using comments.
For an ordinary Kotlin 2.4.0+ project, common kotlin.uuid.Uuid.random() removes the need for a custom platform wrapper. Expect/actual remains an explicit learning constraint here. UUID stabilization.
This saved draft exceeds the editor limit. Download it before resetting; the original is preserved.
An actual in iosMain is shared by its applicable iOS targets. Declarations must have the same package and compatible signatures. NSUUID comes from the Foundation platform library. Expect/actual, official platform UUID example.
Lowercase normalizes platform string casing for this exercise's contract. The val initializer runs when a Note is created, not whenever its ID is read.
The blanket statement that Uuid is experimental is outdated: the core API is stable since Kotlin 2.4.0, while the separate generateV4/generateV7 functions remain experimental. Stable random does not need to be replaced by them. Kotlin 2.4.0, Uuid.random. Android/iOS actual implementations were not compiled here.