Computer scienceProgramming languagesKotlinAdvanced featuresMultiplatform

Multiplatform overview

Theory

Creating a cross-platform greeting

Report a typo

Hello! This problem might seem a bit unpredictable, but give it a try and tell us how you do!

A Kotlin Multiplatform project needs an easy way to print a greeting message that shows the platform the code is running on. The project should use a common multiplatform structure, using the `expect`/`actual` mechanism to provide platform-specific implementations. The code is written but mixed up. Your job is to put the code lines in order so that the greeting message can show the name of the platform (for example, "Kotlin/Native" for native platforms) and then print that message when the main function runs.

Reorder lines using drag or arrows. Adjust indentation with left buttons
                println(greeting)
              
                expect fun platformName(): String
              
                fun main() {
              
                actual fun platformName(): String {
              
                fun hello(): String = "Hello from ${platformName()}"
              
                }
              
                val greeting = hello()
              
                return "Kotlin/Native"
              
                }
              
___

Create a free account to access the full topic