We'll use Kotlins Multiplatform Project to write a library with code that can be shared across multiple platforms. The list of supported platforms can be found in the Kotlin documentation.
.
├── app // standard Android app project
├── iosApp // standard Swift iOS project
└── sharedcode // shared code library
└── src
├── androidMain
│ └── kotlin // contains actual code for android
├── commonMain
│ └── kotlin // contains shared code and declares expected platform code
└── iosMain
└── kotlin // contains actual code for iOS
You can find documentation about Platform-Specific Declarations (expect
and actual
) in the Kotlin reference.
Some examples, not exhaustive:
data
classes, JSON parsing- Models
- Repositories
- Business Logic
- API client build e.g. with Ktor
- Utility classes
There's a list with libraries that already are multiplatform-enabled.
After you have decided on the feature you want to add to the community app and the shared library:
- Create a folder where the actual app for your platform lives in (e.g. iosApp, webApp, desktopApp, ...)
- Create a kotlin file
sharedcode\commonMain\kotlin
, declare shared code as well asexpect
code and classes in there - Create a kotlin file in e.g.
sharedcode\iosMain\kotlin
for each target with the same filename containing theactual
platform specific implementation
Here are some stupid examples to kickstart your creativity:
- Use the NASA API to warn us from geomagnetic storms during our next meetup
- Create a voting and suggestion system for the next meetup topic
- Create a countdown and fetch infos for the next meetup
- Tell users about missed movie releases due to the next meetup (TMDB API)
Get Crazy!
- Kotlin Hands-On: Introduction to Kotlin Multiplatform
- Kotlin Hands-On: Targeting iOS and Android
- Kotlin Reference: Multiplatform Programming
- Readme: Coroutines and multiplatform / native
- Tutorial: Kotlin Multiplatform Project for Android and iOS: Getting Started
- Tutorial: A practical Intro to Kotlin Multiplatform