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

kmp-iosmeetup.pdf

 kmp-iosmeetup.pdf

Overview of Kotlin Multiplatform for the iOSoho meetup in NYC

Kevin Galligan

January 14, 2019
Tweet

More Decks by Kevin Galligan

Other Decks in Programming

Transcript

  1. Kotlin Multiplatform For iOS Kevin Galligan

  2. None
  3. Touchlab

  4. Community community!

  5. None
  6. Multiplatform Ambassador (unofficial) http://talkingkotlin.com/

  7. What is Kotlin Multiplatform?

  8. 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.
  9. Optional Sharing Low risk. No Big Decisions.

  10. Natively Integrated smooth interop

  11. open source

  12. Code Sharing not “cross platform”

  13. popular

  14. popular

  15. popular

  16. language & tools

  17. modern

  18. Not UI well, not necessarily UI

  19. Shared UI == Failure!

  20. Shared Logic == Computers

  21. Many Platforms

  22. Kotlin

  23. Kotlin JVM

  24. Kotlin JVM JS

  25. Kotlin JVM JS Native

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

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

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

    Webassembly Many Platforms
  29. Why Kotlin? High Efficiency Low Risk Modern Language/Tools Highly Engaged

    Community
  30. mobile is easy

  31. mobile is easy

  32. Status

  33. Q3 Q2 Q4 Q1 Q2 2018 2019 0 .6 v0.7

    v0.8 v0.8.2 v0.9.3 IDE tooling! Coroutines?
  34. 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+
  35. 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
  36. 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
  37. 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”
  38. TL;DR March start getting real end of Q1

  39. SHARED CODE FOR ANDROID & IOS

  40. Common

  41. Common mainThread?

  42. expect val mainThread:Boolean

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

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

    === Looper.getMainLooper() actual val mainThread: Boolean get() = NSThread.isMainThread()
  45. 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
  46. expect fun currentTimeMillis():Long expect fun <B> backgroundTask(backJob:()-> B, mainJob:(B) ->

    Unit) expect fun backgroundTask(backJob:()->Unit) expect fun networkBackgroundTask(backJob:()->Unit) expect fun initContext():NativeOpenHelperFactory expect fun <T> goFreeze(a:T):T expect fun <T> T.freeze2(): T expect fun simpleGet(url:String):String expect fun logException(t:Throwable) expect fun settingsFactory(): Settings.Factory expect fun createUuid():String
  47. expect class Date { fun toLongMillis():Long } expect class DateFormatHelper(format:String){

    fun toDate(s:String):Date fun format(d:Date):String }
  48. 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) }
  49. fun initPlatformClient( staticFileLoader: (filePrefix: String, fileType: String) -> String?, analyticsCallback:

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

    (name: String, params: Map<String, Any>) -> Unit, clLogCallback: (s: String) -> Unit) { AppContext.initPlatformClient ({filePrefix, fileType -> loadAsset("${filePrefix}.${fileType}")}, {name: String, params: Map<String, Any> -> val event = CustomEvent(name) //Loop Answers.getInstance().logCustom(event) }, { Log.w("MainApp", it) })
  51. 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 } }
  52. interface SessionDetailsView : BaseView { fun updateView(isFavorite: Boolean, session: SessionModel)

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

    fun setupRatingButtons(rating: SessionRating?) fun setRatingClickable(clickable: Boolean) }
  54. Common

  55. JVM Native Common

  56. JVM Native Common Framework

  57. JVM Native Common Framework

  58. JVM Native Common Android Stuff Framework iOS Stuff

  59. OK, and?!

  60. Industry Level for everybody

  61. Platform Consolidation

  62. None
  63. Mobile Needs An Answer everything is mobile

  64. #postplatform all the same shit

  65. Mobile Oriented Architecture (MOA)

  66. ?

  67. Personal Level for you, specifically

  68. None
  69. “…upstart skills like Kotlin are also in high demand”

  70. Future Proof relevant for the next decade +

  71. Libraries! Libraries! Libraries!

  72. great time to start

  73. Jetbrains • Ktor • Kotlinx.Coroutines • Kotlinx.io • Kotlinx.serialization •

    Atomic-fu (maybe?)
  74. Community • Sqldelight • Knarch.db • Multiplatform Settings • Stately

    • OKIO2 (developing) • Timber (sort of)
  75. Getting Started

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

  77. Sample Apps the conference apps

  78. None
  79. https://github.com/touchlab/DroidconKotlin/

  80. iOS Specific Instructions look for ‘IOSDEV.md’

  81. kevin@touchlab.co @kpgalligan