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

SwiftUIで変わるiOS開発

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)

Takaaki Tanaka

September 25, 2019
Tweet

More Decks by Takaaki Tanaka

Other Decks in Technology

Transcript

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

    SwiftUI ͱ Property Wrappers • ݱ؀ڥͱͷڞଘ
  2. SwiftUI   • WWDC19 Ͱൃද͞Εͨɺ InterfaceBuilder -> Storyboard ʹ͙࣍ɺUIΛߏங͢ΔͨΊͷframework

    • ViewControllerΛհࡏͤ͞ͳ͍৽͍֓͠೦ • ϨΠΞ΢τΛίʔυͰදݱͰ͖ΔͨΊɺAutolayoutͳͲͷ ෳࡶͳ֓೦Λ࢖Θͳ͍Ͱը໘ΛߏஙͰ͖Δ • ϓϨϏϡʔػೳͰίʔσΟϯά͠ͳ͕Βɺ࡞੒தͷը໘ͷ ֬ೝ͕Ͱ͖ΔʢmacOS / CatalinaҎ߱ʣ • DarkMode͕σϑΥϧτͰରԠ
  3. SwiftUI ͱ Property Wrappers   • Property Wrappers ͱ͍͏ػߏΛ࢖ͬͯɺඳըʹӨڹ͋Δ

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

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

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

    ஋Λࢀর͢ΔଆͷViewͷϓϩύςΟʹએݴ͢Δ͜ͱͰɺ ผͷViewͷ @State ͳͲͷ஋ͷߋ৽௨஌Λड͚औΕΔ https://developer.apple.com/videos/play/wwdc2019/226/
  7. SwiftUI ͱ Property Wrappers (ObservableObject)   • ObservableObject ͱ

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

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

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

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

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

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

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

    ඇಉظͳσʔλΛॲཧ͢ΔͨΊͷframeworkͰPub / Sub ͳ࢓૊ΈΛఏڙ
  15. UIHostingController   • طଘͷ UIViewController ʹ SwiftUI Λ૊ΈࠐΉͨΊͷ Controller

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

    AutolayoutΛ࢖Θ͟ΔΛಘͳ͍ঢ়گ͸ൃੜ͢Δ • ೲظ͕ݫ͍͠৔߹͸ Storyboard ͷ΄͏͕ແ೉ • طଘͷ։ൃ؀ڥͱͷڞଘ͸Մೳ • (….͋·Γ΍Γͨ͘͸ͳ͍….)