piannaf’s avatarpiannaf’s Twitter Archive—№ 4,379

  1. Woohoo! Awesome #KotlinMultiplatform presentation from @YeaLikeFriend for @WWCodeMobile The stream was recorded, but if you can't wait here are my notes 🧵
    1. …in reply to @piannaf
      * Kotlin can compile to multiple targets: JVM, iOS, Desktop, WebAssembly, and more * Share code to reduce redundancy * Platform specific code can interact with the platform
      1. …in reply to @piannaf
        Most other cross-platform frameworks share _all_ the code * Missing flexibility * High initial investment and long-term commitment * Dependent on the framework to update for platform changes
        1. …in reply to @piannaf
          KMP: share only what you want * Very flexible * Easily adopted into existing apps * Can use newest Android and iOS technologies because you keep the native apps
          1. …in reply to @piannaf
            How KMM works * Common Kotlin module generates an Android AAR file and iOS Framework * Android app consumes AAR via Gradle as usual * iOS app consumes framework with SPM or Cocoapods as usual * Can include libraries made for KMM or interface with platform-specific libraries
            1. …in reply to @piannaf
              Acronyms: KMP vs KMM * KMP is all the targets * KMM is the mobile targets KMM going beta in the Fall! [Acronyms like this are often confusing. Here's more details touchlab.co/clarifying-kotlin-multiplatform-naming/]
              1. …in reply to @piannaf
                Shared code * A lot of code is not platform specific and can be “common” that essentially gives you multiplatform code for free * Android and iOS code has access to the common code and access to platform specific functionality
                1. …in reply to @piannaf
                  A lot of KMM samples are in the style of "Hello, World!" which is helpful. Sometimes you want more. KaMP Kit is a fully functioning app with networking requests, persistence, and other best practices and preferred libraries github.com/touchlab/KaMPKit
                  1. …in reply to @piannaf
                    Writing Common Code * Anything that doesn’t use platform-specific APIs * Anything that uses a KMP library * Usually business logic, data models, network and databases
                    1. …in reply to @piannaf
                      Sharing Platform Specific Code * Expect/Actual - it works and is great, but can be overused * What’s the screwdriver if you don’t want to be hammering screws into your app? Interfaces!
                      1. …in reply to @piannaf
                        Interfaces let you pass implementations to common module whether a production implementation or test implementation You can even pass in Swift implementations from iOS!
                        1. …in reply to @piannaf
                          Useful KMP Libraries * Ktor by JetBrains for shared networking * SqlDelight by Square for shared database * Kermit by touchlab for shared logging and crash reporting * Koin for shared dependency injection
                          1. …in reply to @piannaf
                            Make your own by leaning into what you already know about interfaces * “How do I do X with KMP” may not return suitable results * “How do I do X on Android” and “How do I do X on iOS” will return results you can use to get started on your own KMM library
                            1. …in reply to @piannaf
                              Multiplatform Settings by Russell Wolf for shared key-value storage is a great example for getting started with building your own libraries github.com/russhwolf/multiplatform-settings
                              1. …in reply to @piannaf
                                Traversing the Kotlin/Swift Barrier * For example: Suspend functions and Flow aren’t easily consumable from iOS * Use callback interface or write a wrapper around the interface * Android consumes as usual * iOS can consume in a more idiomatic way