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

SwiftUIで変わるiOS開発

808ce3d41280c085f8bdc27dce7ea8fb?s=47 Takaaki Tanaka
September 25, 2019

 SwiftUIで変わるiOS開発

iOS/Android Developers Night with HAKATA.swift で発表した資料です。

## 参考文献

### 公式ドキュメント

- [Combine](https://developer.apple.com/documentation/combine)
- [Creating and Combining Views](https://developer.apple.com/tutorials/swiftui/creating-and-combining-views)
- [EnvironmentValues](https://developer.apple.com/documentation/swiftui/environmentvalues)
- [UIHostingController](https://developer.apple.com/documentation/swiftui/uihostingcontroller)
- [UIViewRepresentable](https://developer.apple.com/documentation/swiftui/uiviewrepresentable)
- [Adding Interactivity with Gestures](https://developer.apple.com/documentation/swiftui/gestures/adding_interactivity_with_gestures)

### Blog

- [Get started with SwiftUI](https://www.hackingwithswift.com/articles/194/get-started-with-swiftui)
- [SwiftUI - Understanding Binding](https://medium.com/@martinlasek/swiftui-understanding-binding-8e20269a76bc)
- [[Swift] SwiftUIのチートシート](https://qiita.com/H_Crane/items/eb847ca7fb7a0b9e8073)
- [一部の画面だけSwiftUIを使いたいとき](https://qiita.com/owen/items/73473cd2206afda3c5d4)

808ce3d41280c085f8bdc27dce7ea8fb?s=128

Takaaki Tanaka

September 25, 2019
Tweet

Transcript

  1. 4XJGU6*ͰมΘΔJ04։ൃ  ਫ  J04"OESPJE%FWFMPQFST/JHIUXJUI)","5"TXJGU Ϋϥεϝιουɺ)","5"TXJGUాத޹໌

  2. ࣗݾ঺հ   wΫϥεϝιουגࣜձࣾ w෱ԬΦϑΟεॴଐ w$9ࣄۀຊ෦ wϞόΠϧΞϓϦΤϯδχΞ wαʔόʔαΠυΞϓϦΤϯδχΞ ాத޹໌ @kongmingtrap

  3. HAKATA.swift   wझຯ࢓ࣄͰ4XJGUʹ৮Ε͍ͯΔํ w4XJGUΛ༻͍ͨJ04։ൃʹܞΘ͍ͬͯΔํ w͜Ε͔Β4XJGUͷษڧΛ͸͡ΊΔͱ͍͏ํ wͳΜ͔4XJGU͕޷͖ͩͱ͍͏ํ

  4. ࠓճ࿩͢͜ͱ   • SwiftUI ͕ग़Δલͷ࿩ • SwiftUI ʹ͍ͭͯ •

    SwiftUI ͱ Property Wrappers • ݱ؀ڥͱͷڞଘ
  5. SwiftUI ͕ग़Δલͷ࿩

  6. SwiftUI ͕ग़Δલͷ࿩ ʙAuto LayoutΛऔΓר͘؀ڥͷ࿩ʙ

  7. None
  8. None
  9. Auto Layoutͷੈք͸޿͍

  10. https://qiita.com/inamiy/items/a6f73438b32896ffa81e

  11. http://elhoshino.hatenablog.com/

  12. ਓྨʹAuto Layout͸ૣ͗ͨ͢ ※ݸਓͷҙݟͰ͢

  13. SwiftUIʹ͍ͭͯ

  14. SwiftUIΛֶͿʹ͸   • ެࣜͷνϡʔτϦΞϧΛ৮ͬͯΈΔͷ͕ۙಓ https://developer.apple.com/tutorials/swiftui/creating-and-combining-views

  15. SwiftUI   • WWDC19 Ͱൃද͞Εͨɺ InterfaceBuilder -> Storyboard ʹ͙࣍ɺUIΛߏங͢ΔͨΊͷframework

    • ViewControllerΛհࡏͤ͞ͳ͍৽͍֓͠೦ • ϨΠΞ΢τΛίʔυͰදݱͰ͖ΔͨΊɺAutolayoutͳͲͷ ෳࡶͳ֓೦Λ࢖Θͳ͍Ͱը໘ΛߏஙͰ͖Δ • ϓϨϏϡʔػೳͰίʔσΟϯά͠ͳ͕Βɺ࡞੒தͷը໘ͷ ֬ೝ͕Ͱ͖ΔʢmacOS / CatalinaҎ߱ʣ • DarkMode͕σϑΥϧτͰରԠ
  16. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ

  17. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ

  18. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ • ॻ͍ͨίʔυͷ಺ ༰͕ϦΞϧλΠϜ ͰϓϨϏϡʔʹඳ ը͞ΕΔ

    • ϥΠϒϓϨϏϡʔ ͸macOS / CatalinaҎ߱
  19. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ

  20. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ

  21. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ

  22. SwiftUIͱطଘ෦඼ͷରԠ   [Swift] SwiftUIͷνʔτγʔτ

  23. SwiftUI ͱ Property Wrappers

  24. SwiftUI ͱ Property Wrappers   • Property Wrappers ͱ͍͏ػߏΛ࢖ͬͯɺඳըʹӨڹ͋Δ

    σʔλͷ΍ΓऔΓΛεϚʔτʹߦ͏ https://developer.apple.com/videos/play/wwdc2019/226/
  25. SwiftUI ͱ Property Wrappers   • @State • @Binding

    • ObservableObject • ObservableObject • ˏObservedObject • Environment • @EnvironmentObject • @Environment • ˏGestureState
  26. SwiftUI ͱ Property Wrappers (@State)   • @State •

    UIͷঢ়ଶͱεςʔτม਺Λࣗಈతʹಉظ͢Δ࢓૊Έ • εςʔτม਺Λมߋ͢ΔͱUI͕ߋ৽͞Εɺ·ͨUIΛมߋ ͢Δͱεςʔτม਺͕ߋ৽͞ΕΔ https://developer.apple.com/videos/play/wwdc2019/226/
  27. SwiftUI ͱ Property Wrappers (@State)   https://medium.com/@martinlasek/swiftui-understanding-binding-8e20269a76bc

  28. SwiftUI ͱ Property Wrappers (@State)   https://medium.com/@martinlasek/swiftui-understanding-binding-8e20269a76bc • Ϙλϯૢ࡞Ͱτάϧͨ͠

    showDetailsม਺ͷ಺༰ʹ Ԡͯ͡ɺςΩετʹදࣔ͢ Δ಺༰Λมߋ͢Δ
  29. SwiftUI ͱ Property Wrappers (@Binding)   • @Binding •

    ஋Λࢀর͢ΔଆͷViewͷϓϩύςΟʹએݴ͢Δ͜ͱͰɺ ผͷViewͷ @State ͳͲͷ஋ͷߋ৽௨஌Λड͚औΕΔ https://developer.apple.com/videos/play/wwdc2019/226/
  30. SwiftUI ͱ Property Wrappers (@Binding)   https://medium.com/@martinlasek/swiftui-understanding-binding-8e20269a76bc

  31. SwiftUI ͱ Property Wrappers (@Binding)   https://medium.com/@martinlasek/swiftui-understanding-binding-8e20269a76bc • ToggleTextButton಺ͷॲཧʹΑ

    Δɺ isOn ͷมԽΛ showDetails Ͱड͚ɺͦͷ಺༰ʹԠͯ͡ɺςΩ ετʹදࣔ͢Δ಺༰Λมߋ͢Δ
  32. SwiftUI ͱ Property Wrappers (ObservableObject)   • ObservableObject ͱ

    ˏObservedObject • ஋ͷߋ৽Λ௨஌͢ΔΫϥεΛ ObservableObject ϓϩτ ίϧʹద߹ͤ͞Δͱɺ ˏObservedObject Λએݴͨ͠ϓ ϩύςΟ΁ߋ৽௨஌Λߦ͏Α͏ʹͳΔ https://developer.apple.com/videos/play/wwdc2019/226/
  33. SwiftUI ͱ Property Wrappers (ObservableObject)   https://developer.apple.com/videos/play/wwdc2019/226/

  34. SwiftUI ͱ Property Wrappers (ObservableObject)   https://developer.apple.com/videos/play/wwdc2019/226/ • ObservableObjectΛ

    ద߹ͨ͠ΦϒδΣΫτ ͷมߋ಺༰Λ @ObservedObject Ͱ ఆٛͨ͠ΦϒδΣΫτ ʹରͯ͠ɺมߋ௨஌Λ ૹΕΔ
  35. SwiftUI ͱ Property Wrappers (Environment)   • Environment •

    Viewͷ֊૚શମʹ·͕ͨΔΑ͏ͳઃఆΛڞ༗͢Δ࢓૊Έ https://developer.apple.com/videos/play/wwdc2019/226/
  36. SwiftUI ͱ Property Wrappers (@EnvironmentObject)   • @EnvironmentObject •

    Environment ͷதʹΧελϜͳ஋ΛઃఆͰ͖Δ • ࢠView΁σʔλΛ౉͢ͷʹViewͷ֊૚Λḷ͍ͬͯ͘ඞཁ ͕ͳ͘ͳΔ https://developer.apple.com/videos/play/wwdc2019/226/
  37. SwiftUI ͱ Property Wrappers (@EnvironmentObject)   https://developer.apple.com/videos/play/wwdc2019/226/

  38. SwiftUI ͱ Property Wrappers (@EnvironmentObject)   https://developer.apple.com/videos/play/wwdc2019/226/ • ObservableObjectΛద߹ͨ͠Φ

    ϒδΣΫτͷมߋ಺༰Λ @EnvironmentObject Ͱఆٛ͠ ͨΦϒδΣΫτʹରͯ͠ɺ֤ Viewʹରͯ͠ɺมߋ௨஌ΛૹΕ Δ
  39. SwiftUI ͱ Property Wrappers (@Environment)   • @Environment •

    EnvironmentValues ʹࣄલʹఆٛ͞Ε͍ͯΔ஋Λ࢖͍ɺ Environment શମʹ·͕ͨΔઃఆͷऔಘɺߋ৽͕Ͱ͖Δ https://developer.apple.com/videos/play/wwdc2019/226/
  40. SwiftUI ͱ Property Wrappers (@GestureState)   • @GestureState •

    ಛఆͷViewʹର͢Δ௕ԡ͠΍ճసͳͲͷط஌ͷδΣε νϟʔύλʔϯΛೝࣝ͢Δ • ύλʔϯ͕Ұகͨ࣌͠ʹSwiftUI͸Ϗϡʔͷঢ়ଶΛߋ৽͠ ͨΓɺΞΫγϣϯΛ࣮ߦͨ͠Γ͢ΔͨΊͷίʔϧόοΫΛ ࣮ߦ͢Δ • ৄ͘͠͸ Adding Interactivity with Gestures ΛΈͯͶʂ https://developer.apple.com/documentation/swiftui/gestures/adding_interactivity_with_gestures
  41. SwiftUI ͱ Combine framework

  42. SwiftUI ͱ Combine framework ※͘͝Ұ෦͚ͩ঺հ

  43. SwiftUI ͱ Combine framework   • Combine framework •

    ඇಉظͳσʔλΛॲཧ͢ΔͨΊͷframeworkͰPub / Sub ͳ࢓૊ΈΛఏڙ
  44. SwiftUI ͱ Combine framework   https://developer.apple.com/documentation/combine

  45. SwiftUI ͱ Combine framework   https://developer.apple.com/documentation/combine

  46. ݱ؀ڥͱͷڞଘ

  47. UIHostingController   • طଘͷ UIViewController ʹ SwiftUI Λ૊ΈࠐΉͨΊͷ Controller

    https://developer.apple.com/documentation/swiftui/uihostingcontroller
  48. UIViewRepresentable   • SwiftUI ʹطଘͷ UIView෦඼ Λ૊ΈࠐΉͨΊͷ࢓૊Έ https://developer.apple.com/documentation/swiftui/uiviewrepresentable

  49. ͍͞͝ʹ

  50. iOS 13ະຬͷ։ൃ͸͙͢ʹ΍ΊΔ΂͖ ※ݸਓͷҙݟͰ͢

  51. ͍͞͝ʹ   • SwiftUI ͸ग़ͨ͹͔ΓͷػೳͳͷͰɺ૝ఆ௨ΓʹϨΠΞ΢τ Ͱ͖ͳ͔ͬͨΓ͢Δ • ͲΜͲΜϑΟʔυόοΫ͠Α͏ •

    AutolayoutΛ࢖Θ͟ΔΛಘͳ͍ঢ়گ͸ൃੜ͢Δ • ೲظ͕ݫ͍͠৔߹͸ Storyboard ͷ΄͏͕ແ೉ • طଘͷ։ൃ؀ڥͱͷڞଘ͸Մೳ • (….͋·Γ΍Γͨ͘͸ͳ͍….)
  52. ͱ͍͏Θ͚ͰHAKATA.swiftͰ͓଴ͪͯ͠·͢ʂ   wझຯ࢓ࣄͰ4XJGUʹ৮Ε͍ͯΔํ w4XJGUΛ༻͍ͨJ04։ൃʹܞΘ͍ͬͯΔํ w͜Ε͔Β4XJGUͷษڧΛ͸͡ΊΔͱ͍͏ํ wͳΜ͔4XJGU͕޷͖ͩͱ͍͏ํ