Slide 1

Slide 1 text

Kotlin Multiplatform For iOS Kevin Galligan

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Touchlab

Slide 4

Slide 4 text

Community community!

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Multiplatform Ambassador (unofficial) http://talkingkotlin.com/

Slide 7

Slide 7 text

What is Kotlin Multiplatform?

Slide 8

Slide 8 text

kot·lin mul·ti·plat·form /ˌkätˈlin məltiˈplatfôrm,ˌkätˈlin məltīˈplatfôrm/ noun noun: kotlin multiplatform 1.optional, natively-integrated, open-source, code sharing platform, based on the popular, modern language kotlin. facilitates non-ui logic availability on many platforms.

Slide 9

Slide 9 text

Optional Sharing Low risk. No Big Decisions.

Slide 10

Slide 10 text

Natively Integrated smooth interop

Slide 11

Slide 11 text

open source

Slide 12

Slide 12 text

Code Sharing not “cross platform”

Slide 13

Slide 13 text

popular

Slide 14

Slide 14 text

popular

Slide 15

Slide 15 text

popular

Slide 16

Slide 16 text

language & tools

Slide 17

Slide 17 text

modern

Slide 18

Slide 18 text

Not UI well, not necessarily UI

Slide 19

Slide 19 text

Shared UI == Failure!

Slide 20

Slide 20 text

Shared Logic == Computers

Slide 21

Slide 21 text

Many Platforms

Slide 22

Slide 22 text

Kotlin

Slide 23

Slide 23 text

Kotlin JVM

Slide 24

Slide 24 text

Kotlin JVM JS

Slide 25

Slide 25 text

Kotlin JVM JS Native

Slide 26

Slide 26 text

Kotlin JVM JS Native iOS Mac Linux Windows Android/NDK Others…

Slide 27

Slide 27 text

Kotlin JVM JS Native iOS Mac Linux Windows Android/NDK Others… Webassembly

Slide 28

Slide 28 text

Kotlin JVM JS Native iOS Mac Linux Windows Android/NDK Others… Webassembly Many Platforms

Slide 29

Slide 29 text

Why Kotlin? High Efficiency Low Risk Modern Language/Tools Highly Engaged Community

Slide 30

Slide 30 text

mobile is easy

Slide 31

Slide 31 text

mobile is easy

Slide 32

Slide 32 text

Status

Slide 33

Slide 33 text

Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7 v0.8 v0.8.2 v0.9.3 IDE tooling! Coroutines?

Slide 34

Slide 34 text

Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7 v0.8 v0.8.2 v0.9.3 IDE tooling! Coroutines? K/N 1.0, Kotlin 1.3 Gradle 4.10+

Slide 35

Slide 35 text

Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7 v0.8 v0.8.2 v0.9.3 IDE tooling! Coroutines? K/N 1.0, Kotlin 1.3 Gradle 4.10+ K/N 1.1, Kotlin 1.3.20 Community Libraries Big Co Support

Slide 36

Slide 36 text

Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7 v0.8 v0.8.2 v0.9.3 IDE tooling! Coroutines? K/N 1.0, Kotlin 1.3 Gradle 4.10+ K/N 1.1, Kotlin 1.3.20 Community Libraries Big Co Support MT Coroutines Improved tooling

Slide 37

Slide 37 text

Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7 v0.8 v0.8.2 v0.9.3 IDE tooling! Coroutines? K/N 1.0, Kotlin 1.3 Gradle 4.10+ K/N 1.1, Kotlin 1.3.20 Community Libraries Big Co Support MT Coroutines Improved tooling Reactive Library Big Prod Apps “Mainstream”

Slide 38

Slide 38 text

TL;DR March start getting real end of Q1

Slide 39

Slide 39 text

SHARED CODE FOR ANDROID & IOS

Slide 40

Slide 40 text

Common

Slide 41

Slide 41 text

Common mainThread?

Slide 42

Slide 42 text

expect val mainThread:Boolean

Slide 43

Slide 43 text

expect val mainThread:Boolean actual val mainThread: Boolean get() = Looper.myLooper() === Looper.getMainLooper()

Slide 44

Slide 44 text

expect val mainThread:Boolean actual val mainThread: Boolean get() = Looper.myLooper() === Looper.getMainLooper() actual val mainThread: Boolean get() = NSThread.isMainThread()

Slide 45

Slide 45 text

expect val mainThread:Boolean actual val mainThread: Boolean get() = Looper.myLooper() === Looper.getMainLooper() actual val mainThread: Boolean get() = NSThread.isMainThread() actual val mainThread: Boolean = true

Slide 46

Slide 46 text

expect fun currentTimeMillis():Long expect fun backgroundTask(backJob:()-> B, mainJob:(B) -> Unit) expect fun backgroundTask(backJob:()->Unit) expect fun networkBackgroundTask(backJob:()->Unit) expect fun initContext():NativeOpenHelperFactory expect fun goFreeze(a:T):T expect fun T.freeze2(): T expect fun simpleGet(url:String):String expect fun logException(t:Throwable) expect fun settingsFactory(): Settings.Factory expect fun createUuid():String

Slide 47

Slide 47 text

expect class Date { fun toLongMillis():Long } expect class DateFormatHelper(format:String){ fun toDate(s:String):Date fun format(d:Date):String }

Slide 48

Slide 48 text

actual class Date(val iosDate:NSDate) { actual fun toLongMillis():Long{ return floor(iosDate.timeIntervalSince1970).toLong() * 1000L } } actual class DateFormatHelper actual constructor(format:String){ val formatter:NSDateFormatter init { formatter = NSDateFormatter() formatter.dateFormat = format } actual fun toDate(s:String):Date = Date(formatter.dateFromString(s)!!) actual fun format(d:Date):String = formatter.stringFromDate(d.iosDate) }

Slide 49

Slide 49 text

fun initPlatformClient( staticFileLoader: (filePrefix: String, fileType: String) -> String?, analyticsCallback: (name: String, params: Map) -> Unit, clLogCallback: (s: String) -> Unit) {

Slide 50

Slide 50 text

fun initPlatformClient( staticFileLoader: (filePrefix: String, fileType: String) -> String?, analyticsCallback: (name: String, params: Map) -> Unit, clLogCallback: (s: String) -> Unit) { AppContext.initPlatformClient ({filePrefix, fileType -> loadAsset("${filePrefix}.${fileType}")}, {name: String, params: Map -> val event = CustomEvent(name) //Loop Answers.getInstance().logCustom(event) }, { Log.w("MainApp", it) })

Slide 51

Slide 51 text

let appContext = AppContext() appContext.doInitPlatformClient(staticFileLoader: loadAsset, analyticsCallback: analyticsCallback, clLogCallback: csLog) func loadAsset(filePrefix:String, fileType:String) -> String?{ do{ let bundleFile = Bundle.main.path(forResource: filePrefix, ofType: fileType) return try String(contentsOfFile: bundleFile!) } catch { return nil } }

Slide 52

Slide 52 text

interface SessionDetailsView : BaseView { fun updateView(isFavorite: Boolean, session: SessionModel) fun setupRatingButtons(rating: SessionRating?) fun setRatingClickable(clickable: Boolean) }

Slide 53

Slide 53 text

interface SessionDetailsView : BaseView { fun updateView(isFavorite: Boolean, session: SessionModel) fun setupRatingButtons(rating: SessionRating?) fun setRatingClickable(clickable: Boolean) }

Slide 54

Slide 54 text

Common

Slide 55

Slide 55 text

JVM Native Common

Slide 56

Slide 56 text

JVM Native Common Framework

Slide 57

Slide 57 text

JVM Native Common Framework

Slide 58

Slide 58 text

JVM Native Common Android Stuff Framework iOS Stuff

Slide 59

Slide 59 text

OK, and?!

Slide 60

Slide 60 text

Industry Level for everybody

Slide 61

Slide 61 text

Platform Consolidation

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Mobile Needs An Answer everything is mobile

Slide 64

Slide 64 text

#postplatform all the same shit

Slide 65

Slide 65 text

Mobile Oriented Architecture (MOA)

Slide 66

Slide 66 text

?

Slide 67

Slide 67 text

Personal Level for you, specifically

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

“…upstart skills like Kotlin are also in high demand”

Slide 70

Slide 70 text

Future Proof relevant for the next decade +

Slide 71

Slide 71 text

Libraries! Libraries! Libraries!

Slide 72

Slide 72 text

great time to start

Slide 73

Slide 73 text

Jetbrains • Ktor • Kotlinx.Coroutines • Kotlinx.io • Kotlinx.serialization • Atomic-fu (maybe?)

Slide 74

Slide 74 text

Community • Sqldelight • Knarch.db • Multiplatform Settings • Stately • OKIO2 (developing) • Timber (sort of)

Slide 75

Slide 75 text

Getting Started

Slide 76

Slide 76 text

Join Kotlin Slack https://slack.kotlinlang.org

Slide 77

Slide 77 text

Sample Apps the conference apps

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

https://github.com/touchlab/DroidconKotlin/

Slide 80

Slide 80 text

iOS Specific Instructions look for ‘IOSDEV.md’

Slide 81

Slide 81 text

[email protected] @kpgalligan