Slide 1

Slide 1 text

Kotlin native in 10 slides

Slide 2

Slide 2 text

@MartinBonnin apollographql/apollo-android Hearthsim/HSTracker

Slide 3

Slide 3 text

● Created in 2011 by Jetbrains ● Type inference, nullability, extension functions, lambdas, etc... 1. What is Kotlin ?

Slide 4

Slide 4 text

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" } } }

Slide 5

Slide 5 text

3. Compiling to native code Kotlin Compiler FrenchKit.kt LLVM IR LLVM Machine code Kotlin Tooling hello.framework frenchkit.class

Slide 6

Slide 6 text

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;

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

6. Consuming Frameworks ● Monorepo + build phase ● Cocoapods ● Host compiled binaries?

Slide 9

Slide 9 text

7. It works!

Slide 10

Slide 10 text

8. Debugging

Slide 11

Slide 11 text

9. KMM (Kotlin Multiplatform Mobile)

Slide 12

Slide 12 text

● 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

Slide 13

Slide 13 text

● Ecosystem ○ SQL Delight ○ Ktor ○ Blue-Falcon ○ Koin ● Samples ○ joreilly/PeopleInSpace ○ JetBrains/kotlinconf-app ○ HearthSim/HSTracker Conclusion

Slide 14

Slide 14 text

● Memory model ○ Jetbrains Memory Management Roadmap ○ Kotlin native concurrency explained ○ Why the K/N memory model cannot hold Resources

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Merci! @MartinBonnin bit.ly/10-min-of-kotlin