connectla.blogg.se

Kotlin multiplatform ios example
Kotlin multiplatform ios example






It specifies that there should be a platform-specific implementation of an object that conforms to the Logger interface, provided by Ktor:

kotlin multiplatform ios example

Here is the expected definition of a platform-specific HTTP request / response logger.

kotlin multiplatform ios example

Let’s take a look at how we can use the expect/actual mechanism to implement logging in a multiplatform project.

  • expect declarations do not contain any implementation and are abstract by default.ĭuring the compilation of each platform, the compiler makes sure that every expected declaration in the common or intermediate module has a corresponding actual declaration in each platform source set.
  • kotlin multiplatform ios example

    expect and actual declarations have the same name and be in the same package (having the same fully qualified name).An expected declaration is marked with the expect keyword and an actual declaration is marked with the actual keyword.When using expected and actual definitions, some basic rules need to be followed: This works for functions, classes, interfaces, enumerations, properties and annotations. This mechanism requires an expected definition to be declared in the common source set and a corresponding actual definition to be declared in the platform source sets. The mechanism of expected and actual definitions can be used in a multiplatform application that needs to access platform-specific functionality. All of these have very different representations across the different platforms and it is not possible to share them. Almost every application will need to deal with some platform-specific stuff such as I/O, files, dates, encryption and hashing, UUIDs. Sharing code in the common module is great but, sadly, not possible all the time. This is Part 2 of a series, so make sure to check out Part 1: Sharing Application logic with Kotlin Multiplatform.

    kotlin multiplatform ios example

    This blog post looks at interfacing with platform-specific code using Kotlin Multiplatform.








    Kotlin multiplatform ios example