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

Demystify SwiftUI 要約 / Summary of Demystify Swi...

Demystify SwiftUI 要約 / Summary of Demystify SwiftUI

Elvis Shi

June 28, 2021
Tweet

More Decks by Elvis Shi

Other Decks in Programming

Transcript

  1. %FNZTUJGZ4XJGU6*ཁ໿ f o r  : 6 . & .

    *  T X J G U      G F BU   ) " , "5"  T X J G U  
 ʙ 8 8 % $  3F DBQ ʙ
  2. } var employedBy = "YUMEMI Inc." var job = "iOS

    Tech Lead" var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ Πψ೿Ͱ͕͢ɺԿ͔ʁ """ final class Me: Developable, Talkable {
  3. &YQMJDJU*EFOUJUZʹٻΊΒΕΔੑ࣭ w ϢχʔΫੑ w ଞͷର৅ͱඃͬͯ͸͍ ͚ͳ͍ w ෆมੑ w ͍ͭɺԿճݺͼग़ͯ͠

    ΋มΘͬͯ͸͍͚ͳ͍ ForEach(cats, id: \.name) { cat in Text("\(cat.age)ࡀ") } Explicit Identity
  4. 4USVDUVSBM*EFOUJUZͱͷ෇͖߹͍ํ w ಉ͡ϏϡʔͳΒɺ෼ذΛ ͯ͠͸ߦ͚ͳ͍ w ෼ذΛͤͣʹ͏·͘ *OFSU.PEJ fi FSͳͲΛ ׆༻

    Structural Identity if flag { Text("A") } else { Text("B") } ద༻ͯ͠΋ϏϡʔͷඳըʹӨڹ͠ͳ͍.PEJ fi FSɻ  PQBDJUZ    QBEEJOH    FUD
  5. -JGFUJNF w 4XJGU6*ͷϏϡʔλΠϓ͸஋ܕ w ϏϡʔλΠϓ͸ͨͩͷϏϡʔඳըϨγϐ w ϏϡʔλΠϓͷΠϯελϯεࣗମ͸ඇৗʹ୹໋ w ͔͠͠Ϗϡʔͷੜଘظؒ͸΋ͬͱ௕͍ w

    Ϗϡʔ͸ඞཁ͕͋ͬͨΒੜ੒͞Εɺඞཁͳ͘ͳͬͨΒফ͞ΕΔ w ੜ੒͞ΕͨΒonAppearɺফ͞ΕͨΒonDisappear͕ݺ ͹ΕΔ w @State΍@StateObject΋Ϗϡʔ͕ඞཁͳ͘ͳͬͨΒফ ͞ΕΔ
  6. -JGFUJNF fl BHUSVF  UBQ ࣌ؒ fl BHGBMTF struct Demo:

    View { var flag: Bool var body: some View { if flag { Counter() .background(Color.blue) } else { Counter() .background(Color.red) } } } struct Counter: View { @State private var count = 0 var body: some View { Text("\(count)") .onTapGesture { count += 1 } } }    fl BHUSVF   ফ͞ΕΔ
  7. -JGFUJNF fl BHUSVF  UBQ ࣌ؒ fl BHGBMTF struct Demo:

    View { var flag: Bool var body: some View { Counter() .background( flag ? Color.blue : Color.red ) } } struct Counter: View { @State private var count = 0 var body: some View { Text("\(count)") .onTapGesture { count += 1 } } }   fl BHUSVF  ফ͞Εͳ͍ Dependency