Swiftのクロージャーで苦労じゃ〜

 Swiftのクロージャーで苦労じゃ〜

Swiftのクロージャーについての説明資料です

Transcript

  1. SwiftͷΫϩʔδϟʔͰ ۤ࿑͡Όʙ ͔Β·͛ˏ͏·͏·ͩΑ΋Μ

  2. ࣗݾ঺հ ໊લɹ֟ຊڡষˏ͔Β·͛ ৬ۀɹϑϦʔϥϯεɾΤϯδχΞ WebΞϓϦ΍iOSΞϓϦΛ࡞Δ࢓ࣄΛ͍ͯ͠·͢ɻ ग़਎஍ɹ෱Ԭ Swift, Ruby,JS, AWS Lambda https://www.facebook.com/karamage.umauma

  3. ࣗ༝ͳελΠϧͰ࢓ࣄͯ͠·͢ ΋;΋;͠ͳ͕Βϓϩάϥϛϯά

  4. Swift ೉͍͠ ࢛ఱԦ Ẃࠈͷ$MPTVSF మนͷHVBSE ࠞಱͷ0QUJPOBM ັ࿭ͷQSPUPDPM

  5. Ϋϩʔδϟʔ஌ͬͯ·͔͢ʁ Š8JLJQFEJBΑΓŠ ΫϩʔδϟʢΫϩʔδϟʔɺӳDMPTVSFʣ ؔ਺ดแ͸ϓϩάϥϛϯάݴޠʹ͓͚Δؔ਺ΦϒδΣΫτͷҰछɻ ͍͔ͭ͘ͷݴޠͰ͸ϥϜμࣜ΍ແ໊ؔ਺Ͱ࣮ݱ͍ͯ͠Δɻ

  6. ʂʁ

  7. Ϋϩʔδϟʔͱ͸ؔ਺Ͱ͋Δɻ

  8. Ϋϩʔδϟʔʹ͸໊લ͕ͳ͍

  9. Ϋϩʔδϟʔ = ໊ແ͠ͷؔ਺

  10. อଘ֬ೝΞϥʔτදࣔ

  11. Ϋϩʔδϟʔ࢖ͬͯ·͔͢ʁ MFUEFGBVMU"DUJPO6*"MFSU"DUJPO 6*"MFSU"DUJPO UJUMF0, TUZMF6*"MFSU"DUJPO4UZMF%FGBVMU  IBOEMFS\ Ϙλϯ͕ԡ͞Εͨ࣌ͷॲཧΛॻ͘ʢΫϩʔδϟ࣮૷ʣ  BDUJPO6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U l)FMMPz ^Ҿ਺লུ
  19. ೉͍͠ɻɻɻʼʻ

  20. Ϋϩʔδϟʔͷ࢖͍υίϩ ɾίʔϧόοΫ/ඇಉظॲཧ - Alamofire౳ ɾϦΞΫςΟϒϓϩάϥϛϯά RxSwift/SwiftBond ɾmap/filter/reduce

  21. ΫϩʔδϟʔͰඇಉظॲཧ ɾඇಉظॲཧͱ͔ͰΑ͘࢖͏ "MBNPpSFSFRVFTU (&5 IUUQTRJJUBDPNBQJWJUFNT  SFTQPOTF+40/\SFTQPOTFJO ͜͜ʹॲཧΛهड़͍ͯ͘͠ ^

  22. ઀ඌΫϩʔδϟʔ(Trailing Closure) ຤ඌҾ਺ʹΫϩʔδϟΛࢦఆͨؔ͠਺Λݺͼग़͢ࡍɺ Χοίॻ͖ΛলུͰ͖·͢ɻ ΧοίΛলུ͠ͳ͍৔߹ɺϝιουͷΧοί ͷ֎ʹΫϩʔδϟΛॻ͚Δ

  23. ઀ඌΫϩʔδϟʔͰsort OVNCFSTTPSUFE \ OVN*OU OVN*OU #PPMJO SFUVSOOVNOVN ^

  24. ·ͱΊ ɾΫϩʔδϟʔ͸໊ແ͠ͷؔ਺ ɾΫϩʔδϟʔΛ࢖͏ͱඇಉظॲཧͳͲ͕ॻ ͖΍͍͢ ɾ઀ඌΫϩʔδϟʔ͸Χοίͷ֎ʹॻ͚Δ

  25. Ϋϩʔδϟʔͷม਺Ωϟϓνϟ to be continued…

  26. ͝੩ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠