Slide 1

Slide 1 text

KOTLIN FOR SWIFT DEVELOPERS (SWIFT εЀυϘί΄͵Η΄KOTLIN) TRY! SWIFT | TOKYO, JAPAN | MARCH 2018 @DESIGNATEDNERD | BAKKENBAECK.COM | JUSTHUM.COM

Slide 2

Slide 2 text

HEY, @d_date THANK YOU FOR THE TRANSLATION! (෭๜承΅扖ͭΔͱ

Slide 3

Slide 3 text

!"

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

✨ " ☕ $ ✨

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

WHAT IS KOTLIN ? ( KOTLIN ᥺承͹ͼ֜ Ҙ)

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

WHY SHOULD I CARE? ( ΀Ͳᐺ΅䶲΁ͯΡ΄͡?)

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

A CONSTANT STRING

Slide 22

Slide 22 text

SWIFT let greeting = "Hello World"

Slide 23

Slide 23 text

SWIFT let greeting = "Hello World" KOTLIN val greeting = "Hello World"

Slide 24

Slide 24 text

AN OPTIONAL INTEGER VARIABLE

Slide 25

Slide 25 text

SWIFT var something: Int?

Slide 26

Slide 26 text

SWIFT var something: Int? KOTLIN var something: Int?

Slide 27

Slide 27 text

☠ NullPointerException ☠

Slide 28

Slide 28 text

!"

Slide 29

Slide 29 text

GENERICS AND FUNCTIONS AS PARAMETERS ( Ϟ϶ϮЄό;ͭͼֵ͞Ρ樛හ)

Slide 30

Slide 30 text

SWIFT func useFunction(on item: T, function: (T) -> U) -> U { return function(item) } func insertExclamationPoint(in string: String) -> String { return string .components(separatedBy: " ") .joined(separator: "! ") } let result = useFunction(on: "try Swift", function: insertExclamationPoint(in:)) // result: "try! Swift"

Slide 31

Slide 31 text

KOTLIN fun T.useFunction(action: (T) -> U): U { return action(this) } fun insertExclamationPoint(in: String) : String { return in.split(" ").joinToString("! ") } val result = "try Kotlin".useFunction { insertExclamationPoint(it) } // result: "try! Kotlin"

Slide 32

Slide 32 text

map filter reduce

Slide 33

Slide 33 text

map filter reduce*

Slide 34

Slide 34 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(0, +) // reduced: 6

Slide 35

Slide 35 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(0, +) // ! // reduced: 6

Slide 36

Slide 36 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(0) { $0 + $1 } // reduced: 6

Slide 37

Slide 37 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26

Slide 38

Slide 38 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26 KOTLIN val numbers = arrayOf(1, 2, 3) val reduced = numbers.reduce { total, current -> total + current } // reduced: 6

Slide 39

Slide 39 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26 ⬆ KOTLIN val numbers = arrayOf(1, 2, 3) val reduced = numbers.reduce { total, current -> total + current } // reduced: 6

Slide 40

Slide 40 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26 KOTLIN val numbers = arrayOf(1, 2, 3) val folded = numbers.fold(20) ⬅ { total, current -> total + current } // folded: 26

Slide 41

Slide 41 text

SWIFT let doubled = [ 1, 2, 3 ].map { $0 * 2 }

Slide 42

Slide 42 text

SWIFT let doubled = [ 1, 2, 3 ].map { $0 * 2 } KOTLIN arrayOf(1, 2, 3).map { it * 2 }

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

SWIFT let doubled = [ 1, 2, 3 ].map { $0 * 2 } KOTLIN arrayOf(1, 2, 3).map { it * 2 }

Slide 46

Slide 46 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26

Slide 47

Slide 47 text

$0 $1 $2...$∞

Slide 48

Slide 48 text

SWIFT let numbers = [ 1, 2, 3 ] let reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26 KOTLIN val numbers = arrayOf(1, 2, 3) val folded = numbers.fold(20) { total, current -> total + current } // folded: 26 ⬆

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

!"#

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

guard

Slide 53

Slide 53 text

NOW (匍ࣁ) (KOTLIN) optionalThing?.let { it.doSomething() }

Slide 54

Slide 54 text

NOW (匍ࣁ) (WORSE KOTLIN) if (optionalThing != nil) { optionalThing!!.doSomething() }

Slide 55

Slide 55 text

PROPOSED (൉ໜ) (KOTLIN) guard val thing = optionalThing else { return } thing.doSomething()

Slide 56

Slide 56 text

apply

Slide 57

Slide 57 text

NOW (匍ࣁ) (SWIFT) UserDefaults.standard.set(true, forKey: "DefaultOne") UserDefaults.standard.set(false, forKey: "DefaultTwo)

Slide 58

Slide 58 text

NOW (匍ࣁ) (BETTER SWIFT) let defaults = UserDefaults.standard defaults.set(true, forKey: "DefaultOne") defaults.set(false, forKey: "DefaultTwo)

Slide 59

Slide 59 text

PROPOSED (൉ໜ) (SWIFT) UserDefaults.standard.apply { "DefaultOne" = true, "DefaultTwo" = false, }

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

KOTLIN / NATIVE

Slide 63

Slide 63 text

LLVM

Slide 64

Slide 64 text

LLVM

Slide 65

Slide 65 text

LLVM

Slide 66

Slide 66 text

SUPPORTED PLATFORMS ▸ x86-64 (macOS, Linux, Windows) ▸ arm64 (iOS, Android) ▸ arm32 (Android) ▸ arm32 hardfp (Raspberry Pi) ▸ WebAssembly (Web)

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

DOCUMENTATION

Slide 70

Slide 70 text

DOCUMENTATION? ¯\_(ϑ)_/¯

Slide 71

Slide 71 text

KOTLIN: ☕ OR " = #

Slide 72

Slide 72 text

try? kotlin

Slide 73

Slide 73 text

https://try.kotlinlang.org

Slide 74

Slide 74 text

No content

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

EDU TOOLS PLUGIN FOR INTELLIJ OR ANDROID STUDIO (INTELLIJ Δ͵΅ ANDROID STUDIO አ΄Ϥ϶ναЀ)

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

OBLIGATORY SUMMARY SLIDE (嬝㵗ጱ΀ᥝ夹) ▸

Slide 80

Slide 80 text

OBLIGATORY SUMMARY SLIDE (嬝㵗ጱ΀ᥝ夹) ▸ Make Friends With Android ▸ (Android ;լᜉͥ΀Σ͜)

Slide 81

Slide 81 text

OBLIGATORY SUMMARY SLIDE (嬝㵗ጱ΀ᥝ夹) ▸ Make Friends With Android ▸ (Android ;լᜉͥ΀Σ͜) ▸ Kotlin Native Is Cool But Not Ready For Production ▸ (Kotlin Native΅͡͹̵͚͚ͩ͢ϤϺύ μτϴЀ΁΅ΔͶֵ͞΀͚)

Slide 82

Slide 82 text

try! Kotlin

Slide 83

Slide 83 text

ONE MORE THING

Slide 84

Slide 84 text

✨ "#$ ✨

Slide 85

Slide 85 text

͘Π͢;͚ͪͬ͜Δͭ͵! (THANK YOU VERY MUCH!)

Slide 86

Slide 86 text

LINKS! ▸ Kotlin Home & Documentation https://kotlinlang.org ▸ KotlinConf iOS App in Kotlin/Native: https://github.com/JetBrains/ kotlinconf-app/tree/master/ios ▸ The Edu Tools Plugin for IntelliJ or Android Studio https://kotlinlang.org/docs/ tutorials/edu-tools-learner.html

Slide 87

Slide 87 text

MORE LINKS! ▸ Creating an iOS Framework With Kotlin http://viteinfinite.com/2018/02/creating-an-ios- framework-with-kotlin

Slide 88

Slide 88 text

ILLUSTRATION CREDITS ▸ Monica Komperda, Native Code Forever (Hire her! She's awesome!) http://mokomperda.com/design