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

if 式と switch 式による SwiftUI のプレビューエラー対策

ojun
November 14, 2023

if 式と switch 式による SwiftUI のプレビューエラー対策

ojun

November 14, 2023
Tweet

More Decks by ojun

Other Decks in Programming

Transcript

  1. Xcode 15.0 Asset Catalogs / String Catalogs PreviewϚΫϩ Swift 5.9

    ϒοΫϚʔΫػೳ ɾෳ਺ͷݴޠػೳͷ௥Ճ ɾσόοά࣌ʹม਺ͷ಺༰Λग़ྗ͢ΔͨΊʹར༻͢ΔpίϚϯυͱpoίϚϯυ ʹΑΔग़ྗ͕࣌ؒେ෯ʹ୹ॖ ͦͷଞ͍Ζ͍Ζ
  2. Xcode 15.0 Asset Catalogs / String Catalogs PreviewϚΫϩ Swift 5.9

    ϒοΫϚʔΫػೳ ɾෳ਺ͷݴޠػೳͷ௥Ճ ͦͷଞ͍Ζ͍Ζ ɾσόοά࣌ʹม਺ͷ಺༰Λग़ྗ͢ΔͨΊʹར༻ՄೳͳpίϚϯυͱpoίϚϯυ ʹΑΔग़ྗ͕࣌ؒେ෯ʹ୹ॖ
  3. Opaque Type Λ Existential Type ʹஔ͖׵͑Δ ໭Γ஋Λany Viewʹ͢Δํ๏ ͨͩ͠ɺݺͼग़͠ݩͰܕΩϟετΛ ߦ͏ඞཁ͕͋Δ

    ௨ৗͷϏϧυ 🎉 ໰୊ͳ͘੒ޭ͢Δ Preview࣌ͷϏϧυ 🎉 ໰୊ͳ͘੒ޭ͢Δ
  4. ·ͱΊ Swift 5.9͔Β͸ if ͱ switch Λࣜͱͯ͠ѻ͑ΔΑ͏ʹͳͬͨ if / switch

    ࣜΛ༻͍ͯSwiftUIͷViewΛʢopaque typeͱͯ͠ʣฦ͢ͱ Preview࣌ͷϏϧυͰͷΈίϯύΠϧΤϥʔ͕ൃੜ͢Δ ҎԼͷ͍ͣΕ͔ͷํ๏Ͱ໰୊ͷରԠΛ͢Δ͜ͱ͕Ͱ͖Δ 1. @ViewBuilderΩʔϫʔυΛ෇༩͢Δ 2. Opaque typeͰ͸ͳ͍໌֬ͳܕΛฦ͢ʢText ͳͲʣ 3. Opaque Type Λ Existential Type ʹஔ͖׵͑Δ