$30 off During Our Annual Pro Sale. View Details »

Kotlin native in 10 min

mbonnin
October 02, 2020

Kotlin native in 10 min

Everything Kotlin native in 10min

mbonnin

October 02, 2020
Tweet

More Decks by mbonnin

Other Decks in Programming

Transcript

  1. Kotlin native in 10 slides

  2. @MartinBonnin apollographql/apollo-android Hearthsim/HSTracker

  3. • Created in 2011 by Jetbrains • Type inference, nullability,

    extension functions, lambdas, etc... 1. What is Kotlin ?
  4. 2. Swift ~ Kotlin class FrenchKit { func hello(name: String?)

    -> String { guard let name_ = name else { return "Hello unknown person" } return "Hello \(name_)" } } class Frenchkit { fun hello(name: String?): String { if (name != null) { return "Hello $name" } else { return "Hello unknown person" } } }
  5. 3. Compiling to native code Kotlin Compiler FrenchKit.kt LLVM IR

    LLVM Machine code Kotlin Tooling hello.framework frenchkit.class
  6. 4. Hello.h __attribute__((objc_subclassing_restricted)) __attribute__((swift_name("FrenchKit"))) @interface HelloFrenchKit : HelloBase - (instancetype)init

    __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); + (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); - (NSString *)helloName:(NSString * _Nullable)name __attribute__((swift_name("hello(name:)"))); @end;
  7. 5. Swift interop Kotlin Swift class class interface protocol String

    String List Array Map Dictionary Function type Function type ∅ Struct Sealed classes, inline classes ∅ https://kotlinlang.org/docs/reference/native/objc_interop.html
  8. 6. Consuming Frameworks • Monorepo + build phase • Cocoapods

    • Host compiled binaries?
  9. 7. It works!

  10. 8. Debugging

  11. 9. KMM (Kotlin Multiplatform Mobile)

  12. • JVM: GC • Objective-C: ARC • K/N: Reference Counting

    + Cycle detector • Variables must be frozen when accessed from multiple threads … • This is all going to change... 10. The memory model Elephant by Josh McGinn
  13. • Ecosystem ◦ SQL Delight ◦ Ktor ◦ Blue-Falcon ◦

    Koin • Samples ◦ joreilly/PeopleInSpace ◦ JetBrains/kotlinconf-app ◦ HearthSim/HSTracker Conclusion
  14. • Memory model ◦ Jetbrains Memory Management Roadmap ◦ Kotlin

    native concurrency explained ◦ Why the K/N memory model cannot hold Resources
  15. Resources • A journey to Kotlin Multiplatform • http://nilhcem.com/swift-is-like-kotlin/ •

    https://kotlinlang.org/docs/reference/native/objc _interop.html • https://kotlinlang.org/docs/reference/native-ove rview.html • https://arnestockmans.be/blog/build-run-jetpac k-compose-for-desktop
  16. Merci! @MartinBonnin bit.ly/10-min-of-kotlin