potatotips #56 (iOS/Android開発Tips共有会)

E222076ea6b90ae53c2bc68c8a4e01f1?s=47 shogo.yamada
November 15, 2018
960

potatotips #56 (iOS/Android開発Tips共有会)

E222076ea6b90ae53c2bc68c8a4e01f1?s=128

shogo.yamada

November 15, 2018
Tweet

Transcript

  1. Copyright © ZOZO Technologies, Inc. All Right Reserved. גࣜձࣾ;0;0ςΫϊϩδʔζ ։ൃ෦ɹࢁాঘޗ

    ෼ͰΘ͔Δ ,PUMJOίϧʔνϯ
  2. ϓϩϑΟʔϧ 5XJUUFS ;0;0ςΫϊϩδʔζ ։ൃ෦ ࢁాঘޗ Copyright © ZOZO Technologies, Inc.

    All Right Reserved. !ZTIPHP (JUIVC !ZTIPHP ݸਓͰ͸'MVUUFSʹϋϚ͍ͬͯΔ
  3. Copyright © ZOZO Technologies, Inc. All Right Reserved. ࠓ೔࿩͢͜ͱ ɾ,PUMJO$PSPVUJOFͬͯͳʹʁʁ

    ɾ࢖͍ํ ɾ"OESPJEͰͲ͏࢖͏ͷ͔ ɾ·ͱΊ
  4. Copyright © ZOZO Technologies, Inc. All Right Reserved. ,PUMJO$PSPVUJOFͬͯͳʹʁʁ "TZODISPOPVTPSOPOCMPDLJOHQSPHSBNNJOHJTUIFOFXSFBMJUZ

    ඇಉظϓϩάϥϛϯά·ͨ͸ඇϒϩοΩϯά ϓϩάϥϛϯά͕৽͍͠ݱ࣮Ͱ͢
  5. Copyright © ZOZO Technologies, Inc. All Right Reserved.

  6. Copyright © ZOZO Technologies, Inc. All Right Reserved. ,PUMJO$PSPVUJOFͬͯͳʹʁʁ XJLJQFEJBͰ$PSPVUJOFΛݕࡧ͢Δͱ

    αϒϧʔνϯ͕ΤϯτϦʔ͔ΒϦλʔϯ·ͰΛҰͭͷॲཧ୯Ґͱ͢Δͷʹର ͠ɺίϧʔνϯ͸͍ͬͨΜॲཧΛதஅͨ͠ޙɺଓ͖͔ΒॲཧΛ࠶։Ͱ͖Δɻ ઀಄ࣙDP͸ڠௐΛҙຯ͢Δ͕ɺෳ਺ͷίϧʔνϯ͕தஅɾܧଓʹΑΓڠௐ ಈ࡞Λߦ͏͜ͱʹΑΔɻ
  7. Copyright © ZOZO Technologies, Inc. All Right Reserved.

  8. Copyright © ZOZO Technologies, Inc. All Right Reserved. ,PUMJO$PSPVUJOFͬͯͳʹʁʁ ʮதஅՄೳͳܭࢉॲཧΠϯελϯεʯ

  9. Copyright © ZOZO Technologies, Inc. All Right Reserved.

  10. Copyright © ZOZO Technologies, Inc. All Right Reserved. ,PUMJO$PSPVUJOFͬͯͳʹʁʁ ཁ͸

    ؔ਺ͷ్தͰதஅͤͨ͞Γɺ࠶։ͨ͠Γ͢Δ΍ͭ
  11. Copyright © ZOZO Technologies, Inc. All Right Reserved. ,PUMJO$PSPVUJOFͬͯͳʹʁʁ "OESPJEͰ͸

    ɾඇಉظॲཧͷ଴ͪ߹Θͤ ɾλΠϜΞ΢τͤ͞Δ ɾ͍ΖΜͳඇಉظॲཧΛҰؾʹࢭΊΔ ͞·͟·ͳඇಉظॲཧΛ؅ཧ͢Δ΋ͷͱߟ͍͍͑ͯ
  12. Copyright © ZOZO Technologies, Inc. All Right Reserved. ,PUMJO$PSPVUJOFͬͯͳʹʁʁ 3Y+BWBͷ୅ସ͑Ͱ͸ͳ͍

    3Y+BWB σʔλϑϩʔΛએݴతʹॻ͘ϦΞΫςΟϒϓϩάϥϛϯά $PSPVUJOF தஅՄೳܭࢉΠϯελϯε
  13. Copyright © ZOZO Technologies, Inc. All Right Reserved. ࢖͍ํ fun

    main() { GlobalScope.launch { delay(1000L) println("World!") } println("Hello,") Thread.sleep(2000L) }
  14. Copyright © ZOZO Technologies, Inc. All Right Reserved. ࢖͍ํ 5JNFPVU

    fun main() = runBlocking { //sampleStart withTimeout(1300L) { repeat(1000) { i -> println("I'm sleeping $i ...") delay(500L) } } //sampleEnd }
  15. ࢖͍ํ ଴ͪ߹Θͤ fun main() = runBlocking<Unit> { //sampleStart val time

    = measureTimeMillis { println("The answer is ${concurrentSum()}") } println("Completed in $time ms") //sampleEnd } suspend fun concurrentSum(): Int = coroutineScope { val one = async { doSomethingUsefulOne() } val two = async { doSomethingUsefulTwo() } one.await() + two.await() } suspend fun doSomethingUsefulOne(): Int { delay(1000L) // pretend we are doing something useful here return 13 } suspend fun doSomethingUsefulTwo(): Int { delay(1000L) // pretend we are doing something useful here, too return 29 }
  16. Copyright © ZOZO Technologies, Inc. All Right Reserved. // retorofit

    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2' // coroutines implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1" ˞,PUMJO͔ΒͷઃఆͰ͢ ઃఆ "OESPJEͰͲ͏࢖͏ͷ͔
  17. Copyright © ZOZO Technologies, Inc. All Right Reserved. interface MainService

    { companion object { const val baseUrl = “URL" } @GET(“/id“) fun getUser(): Deferred<Response<Main>> } 3FUSPpUͱҰॹʹ࢖͏ "OESPJEͰͲ͏࢖͏ͷ͔
  18. Copyright © ZOZO Technologies, Inc. All Right Reserved. fun getUserInfo()

    = Retrofit.Builder() .baseUrl(MainService.baseUrl) .addConverterFactory(MoshiConverterFactory.create()) .addCallAdapterFactory(CoroutineCallAdapterFactory()) .build().create(MainService::class.java) } 3FUSPpUͱҰॹʹ࢖͏ "OESPJEͰͲ͏࢖͏ͷ͔
  19. Copyright © ZOZO Technologies, Inc. All Right Reserved. "OESPJEͰͲ͏࢖͏ͷ͔ GlobalScope.launch

    { val info = repository.getUserInfo() val userRequest = info.getUser() val userResponse = userRequest.await() if (!userResponse.isSuccessful) { ɹɹɹɹɹɹɹɹɹ// ΤϥʔॲཧΛ࣮ߦ͢Δ return@launch } userModel.set(userResponse.body() ?: return@launch) } 3FUSPpUͱҰॹʹ࢖͏
  20. Copyright © ZOZO Technologies, Inc. All Right Reserved. ·ͱΊ ɾ$PSPVUJOFͱ͸ʮؔ਺ͷ్தͰதஅͤͨ͞Γɺ

    ࠶։ͨ͠Γ͢Δ΍ͭʯ ɾ3Y+BWBͷ୅ସ͑Ͱ͸ͳ͍ ɾ3FUSPGJUͱҰॹʹ࢖͑·͢
  21. Copyright © ZOZO Technologies, Inc. All Right Reserved. ίϧʔνϯΛੵۃతʹಋೖ͍ͯͧ͘͠ʂʂ

  22. Copyright © ZOZO Technologies, Inc. All Right Reserved. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠