Skip to content

Instantly share code, notes, and snippets.

@hardik-trivedi
Created December 5, 2020 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardik-trivedi/f7ad2e4ab728a297254afb5119fa39d1 to your computer and use it in GitHub Desktop.
Save hardik-trivedi/f7ad2e4ab728a297254afb5119fa39d1 to your computer and use it in GitHub Desktop.
Usage of expect/actual keyword in KMM
:shared:commonMain:OSInformation.kt
expect fun getOSInformation(): String
:shared:androidMain:OSInformation.kt
actual fun getOSInformation(): String {
print(Build.VERSION_CODES::class.java.fields)
return "${Build.VERSION_CODES::class.java.fields[Build.VERSION.SDK_INT].name} ${Build.VERSION.SDK_INT}"
}
:shared:iOSMain:OSInformation.kt
actual fun getOSInformation(): String {
return "${platform.UIKit.UIDevice.currentDevice.systemName()} ${platform.UIKit.UIDevice.currentDevice.systemVersion}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment