Writing Native Code with Kotlin
If you attempt to compile your project now, you will get a compiler error for each of your expect
functions, because you have not provided actual
implementations for your shiny new macOS target.
You also need to define an entry point before Doubloons4Gold will function properly under macOS.
The first function you will implement is your formatAsCurrency function. Create a new Kotlin file called Currency.kt, this time in macosX64Main/kotlin.
In your new file, implement the same currency formatting that you set up for the JVM. You will be using some unfamiliar-looking APIs that ship with macOS. We will walk you through the code after you enter it.
Listing 25.2 Natively formatting a number (macosX64Main/kotlin/Currency.kt ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.