Slide 1

Slide 1 text

Kotlin Multiplatform 集まれもうやんカレーとKotlin好き!Kotlin愛好会 vol6

Slide 2

Slide 2 text

About Me ● Matthew Vern / Panini ● Twitter: @callipan Github: panpanini ● Mercari, Inc ● Android Engineer (US) ● Kotlin可愛い

Slide 3

Slide 3 text

Summary ● I made a Kotlin Multiplatform project! ● It has an Android and iOS app both backed by a common library

Slide 4

Slide 4 text

Kotlin Multiplatform

Slide 5

Slide 5 text

Kotlin Multiplatform ● https://speakerdeck.com/panini/kotlin-multi-platform ● This time I will actually talk about Kotlin Multiplatform

Slide 6

Slide 6 text

Kotlin Multiplatform ● https://kotlinlang.org/docs/reference/multiplatform.html ● 1 codebase, multiple platforms ○ Android ○ iOS ○ JS ○ (JVM)

Slide 7

Slide 7 text

Kotlin Multiplatform - requirements ● Multiplatform code must be 100% pure Kotlin ● Platform specific code must be referenced using `expect` and `actual`

Slide 8

Slide 8 text

Kotlin Multiplatform - tutorial ● https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html ● Explains how to use `expect` and `actual` mechanism expect fun platformName(): String fun createApplicationScreenMessage() : String { return "Kotlin Rocks on ${platformName()}" }

Slide 9

Slide 9 text

:thinking:

Slide 10

Slide 10 text

Kotlin Multiplatform - tutorial v2.0 ● I want a realistic sample project, that reflects real world usage ● It should perform network operations ● UI should be managed by each platform, so only logic should be shared

Slide 11

Slide 11 text

Lets build!

Slide 12

Slide 12 text

Lets build! ● I wrote some details in this blog, please check it! ● https://tech.mercari.com/entry/2018/12/18/114010 ● I want to build this architecture

Slide 13

Slide 13 text

Lets build! ● First, lets build http client ● Because I’m normally an Android Engineer, lets use Retrofit ● https://square.github.io/retrofit/ ● It lets us make network calls just by creating an interface

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Kotlin Multiplatform - requirements ● Multiplatform code must be 100% pure Kotlin ● Platform specific code must be referenced using `expect` and `actual`

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Ktor ● https://ktor.io ● Kotlin http server ● Kotlin http client

Slide 20

Slide 20 text

Ktor ● https://ktor.io ● Kotlin http server ● Kotlin http client ● Multiplatform support

Slide 21

Slide 21 text

Lets build!!!!

Slide 22

Slide 22 text

Service.kt

Slide 23

Slide 23 text

ViewModel.kt

Slide 24

Slide 24 text

Observable.kt

Slide 25

Slide 25 text

Lets build iOS!!!!

Slide 26

Slide 26 text

Observable.kt

Slide 27

Slide 27 text

Observable.kt

Slide 28

Slide 28 text

Lets open Xcode!!!!

Slide 29

Slide 29 text

Xcode………..

Slide 30

Slide 30 text

SplatMaps.xcproject

Slide 31

Slide 31 text

ViewController.swift

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Lets build Android!!!!

Slide 34

Slide 34 text

SplatoonCoroutine.idea

Slide 35

Slide 35 text

MatchFragment.kt

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Summary ● I made a Kotlin Multiplatform project! ● It has an Android and iOS app both backed by a common library ● Http client is not as easy to use as Retrofit ● return KotlinUnit() is ダサイ... ● Kotlin works anywhere and that makes it 可愛い ● https://github.com/panpanini/SplatMaps-Multiplatform

Slide 38

Slide 38 text

Have a nice Kotlin!