Kotlin for Swift Developers - try! Swift Tokyo, March 2018

Kotlin for Swift Developers - try! Swift Tokyo, March 2018

Video:
https://www.youtube.com/watch?v=JK2s6n80Sl8

Kotlin is a new language born on the JVM that's gained a ton of popularity with Android developers. Learn about its similarities and differences with swift, and a bit about where it's going in the future (though it's not quiiiiite there yet).

C4861b1dfdf3bbb21faec4a1acdf183d?s=128

Ellen Shapiro

March 02, 2018
Tweet

Transcript

  1. KOTLIN FOR SWIFT DEVELOPERS (SWIFT εЀυϘί΄͵Η΄KOTLIN) TRY! SWIFT | TOKYO,

    JAPAN | MARCH 2018 @DESIGNATEDNERD | BAKKENBAECK.COM | JUSTHUM.COM
  2. HEY, @d_date THANK YOU FOR THE TRANSLATION! (෭๜承΅扖ͭΔͱ

  3. !"

  4. None
  5. None
  6. None
  7. None
  8. None
  9. None
  10. None
  11. ✨ " ☕ $ ✨

  12. None
  13. WHAT IS KOTLIN ? ( KOTLIN ᥺承͹ͼ֜ Ҙ)

  14. None
  15. None
  16. None
  17. None
  18. WHY SHOULD I CARE? ( ΀Ͳᐺ΅䶲΁ͯΡ΄͡?)

  19. None
  20. None
  21. A CONSTANT STRING

  22. SWIFT let greeting = "Hello World"

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

    "Hello World"
  24. AN OPTIONAL INTEGER VARIABLE

  25. SWIFT var something: Int?

  26. SWIFT var something: Int? KOTLIN var something: Int?

  27. ☠ NullPointerException ☠

  28. !"

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

  30. SWIFT func useFunction<T, U>(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"
  31. KOTLIN fun <T, U>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"
  32. map filter reduce

  33. map filter reduce*

  34. SWIFT let numbers = [ 1, 2, 3 ] let

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

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

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

    reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26
  38. 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
  39. 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
  40. 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
  41. SWIFT let doubled = [ 1, 2, 3 ].map {

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

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

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

    reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26
  47. $0 $1 $2...$∞

  48. 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 ⬆
  49. None
  50. !"#

  51. None
  52. guard

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

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

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

    return } thing.doSomething()
  56. apply

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

  58. NOW (匍ࣁ) (BETTER SWIFT) let defaults = UserDefaults.standard defaults.set(true, forKey:

    "DefaultOne") defaults.set(false, forKey: "DefaultTwo)
  59. PROPOSED (൉ໜ) (SWIFT) UserDefaults.standard.apply { "DefaultOne" = true, "DefaultTwo" =

    false, }
  60. None
  61. None
  62. KOTLIN / NATIVE

  63. LLVM

  64. LLVM

  65. LLVM

  66. SUPPORTED PLATFORMS ▸ x86-64 (macOS, Linux, Windows) ▸ arm64 (iOS,

    Android) ▸ arm32 (Android) ▸ arm32 hardfp (Raspberry Pi) ▸ WebAssembly (Web)
  67. None
  68. None
  69. DOCUMENTATION

  70. DOCUMENTATION? ¯\_(ϑ)_/¯

  71. KOTLIN: ☕ OR " = #

  72. try? kotlin

  73. https://try.kotlinlang.org

  74. None
  75. None
  76. EDU TOOLS PLUGIN FOR INTELLIJ OR ANDROID STUDIO (INTELLIJ Δ͵΅

    ANDROID STUDIO አ΄Ϥ϶ναЀ)
  77. None
  78. None
  79. OBLIGATORY SUMMARY SLIDE (嬝㵗ጱ΀ᥝ夹) ▸

  80. OBLIGATORY SUMMARY SLIDE (嬝㵗ጱ΀ᥝ夹) ▸ Make Friends With Android ▸

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

    (Android ;լᜉͥ΀Σ͜) ▸ Kotlin Native Is Cool But Not Ready For Production ▸ (Kotlin Native΅͡͹̵͚͚ͩ͢ϤϺύ μτϴЀ΁΅ΔͶֵ͞΀͚)
  82. try! Kotlin

  83. ONE MORE THING

  84. ✨ "#$ ✨

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

  86. 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
  87. MORE LINKS! ▸ Creating an iOS Framework With Kotlin http://viteinfinite.com/2018/02/creating-an-ios-

    framework-with-kotlin
  88. ILLUSTRATION CREDITS ▸ Monica Komperda, Native Code Forever (Hire her!

    She's awesome!) http://mokomperda.com/design