Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kotlin For Swift Developers - CocoaHeads NL, Amsterdam, March 2018

Kotlin For Swift Developers - CocoaHeads NL, Amsterdam, March 2018

Video from this version of the presentation:
https://www.youtube.com/watch?v=Tzgh4OTWv4c

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).

Now with actual links to some books I've been working on!

C4861b1dfdf3bbb21faec4a1acdf183d?s=128

Ellen Shapiro
PRO

March 21, 2018
Tweet

Transcript

  1. KOTLIN FOR SWIFT DEVELOPERS COCOAHEADS NL | AMSTERDAM | MARCH

    2018 @DESIGNATEDNERD | BAKKENBAECK.COM | JUSTHUM.COM
  2. !"

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

  11. None
  12. WHAT IS KOTLIN ?

  13. None
  14. None
  15. None
  16. None
  17. WHY SHOULD I CARE?

  18. None
  19. None
  20. A CONSTANT STRING

  21. SWIFT let greeting = "Hello World"

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

    "Hello World"
  23. AN OPTIONAL INTEGER VARIABLE

  24. SWIFT var something: Int?

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

  26. ☠ NullPointerException ☠

  27. !"

  28. GENERICS AND FUNCTIONS AS PARAMETERS

  29. 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"
  30. 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"
  31. map filter reduce

  32. map filter reduce*

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

    reduced = numbers.reduce(0, +) // reduced: 6
  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) { $0 + $1 } // reduced: 6
  36. SWIFT let numbers = [ 1, 2, 3 ] let

    reduced = numbers.reduce(20) { $0 + $1 } // reduced: 26
  37. 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
  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 folded = numbers.fold(20) ⬅ { total, current -> total + current } // folded: 26
  40. SWIFT let doubled = [ 1, 2, 3 ].map {

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

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

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

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

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

  50. None
  51. guard

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

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

  54. PROPOSED (KOTLIN) guard val thing = optionalThing else { return

    } thing.doSomething()
  55. apply

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

  57. NOW (BETTER SWIFT) let defaults = UserDefaults.standard defaults.set(true, forKey: "DefaultOne")

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

    }
  59. None
  60. None
  61. KOTLIN / NATIVE

  62. LLVM

  63. LLVM

  64. LLVM

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

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

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

  70. KOTLIN: ☕ OR " = #

  71. try? kotlin

  72. https://try.kotlinlang.org

  73. None
  74. None
  75. EDU TOOLS PLUGIN FOR INTELLIJ OR ANDROID STUDIO

  76. None
  77. None
  78. OBLIGATORY SUMMARY SLIDE ▸

  79. OBLIGATORY SUMMARY SLIDE ▸ Make Friends With Android

  80. OBLIGATORY SUMMARY SLIDE ▸ Make Friends With Android ▸ Kotlin

    Native Is Cool But Not Ready For Production
  81. OBLIGATORY SUMMARY SLIDE ▸ Make Friends With Android ▸ Kotlin

    Native Is Cool But Not Ready For Production try! Kotlin
  82. ONE MORE THING

  83. ONE MORE THING: (A SHAMELESS PLUG!)

  84. None
  85. BEDANKT, EN TOT ZIENS!

  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 ▸ RayWenderlich.com Android Avalanche™ https://www.raywenderlich.com/187520/ introducing-the-android-avalanche
  88. ILLUSTRATION CREDITS ▸ Monica Komperda, Native Code Forever (Hire her!

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