Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプ...
Search
ojun
July 05, 2024
Programming
4
530
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプレビュー方法の考察
ojun
July 05, 2024
Tweet
Share
More Decks by ojun
See All by ojun
Swift Evolution かるた
ojun9
2
90
Catch Up with Swift 5.10
ojun9
2
740
Overview: Swift OpenAPI Generator
ojun9
3
1.7k
if 式と switch 式による SwiftUI のプレビューエラー対策
ojun9
1
1.3k
楽しい夏休み!String Catalogs で新しい発見
ojun9
0
1.9k
ユニットテストを学んだ次に知りたかったApple標準APIに対するテストのやり方
ojun9
1
390
ハッカソンにおけるiOSアプリ開発での学びと楽しさ
ojun9
1
320
Other Decks in Programming
See All in Programming
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
flutterkaigi_2024.pdf
kyoheig3
0
130
イベント駆動で成長して委員会
happymana
1
320
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
We Have a Design System, Now What?
morganepeng
50
7.2k
Producing Creativity
orderedlist
PRO
341
39k
Building Applications with DynamoDB
mza
90
6.1k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Gamification - CAS2011
davidbonilla
80
5k
Transcript
potatotips #88 iOS/Android։ൃTipsڞ༗ձ 2024/07/05 @STORES Xcode 16ͷPreviewModifierͱ@Previewable Λ׆༻ͨ͠ޮతͳϓϨϏϡʔํ๏ͷߟ ojun -
DeNA Co., Ltd.
ࣗݾհʢojunʣ • name: ojun • 2023৽ଔೖࣾ • iOSΤϯδχΞ @ojun_9
Xcode 16ͷ PreviewModifier ͱ @Previewable Λ׆༻ͨ͠ޮతͳϓϨϏϡʔํ๏ͷߟ
PreviewModifier ͱ ˏPreviewable ʹ͍ͭͯ
@Previewable ʹ͍ͭͯ @Previewable Xcode 16 ͰՃ͞ΕͨϚΫϩ ϓϩύςΟʔϥούʔʹରͯ͠దԠ͢Δ͜ͱ͕Ͱ͖Δ #Previewͷ෦Ͱ༻Մೳ iOS
ʹؔͯ͠ iOS 18 Ҏ্Ͱಈ࡞͢Δ
None
PreviewModifierʹ͍ͭͯ PreviewModi fi er Xcode 16 ͰՃ͞Εͨprotocol iOS ʹؔͯ͠
iOS 18 Ҏ্Ͱಈ࡞͢Δ
None
None
None
None
None
None
None
None
Context Context
Context Context View
Context Context View
Context Context View
None
͜ͷ2ͭͷػೳΛݟͨ࣌ʹͲ͏ࢥ͍·ͨ͠ ͔ʁ
͜ͷ2ͭͷػೳΛݟͨ࣌ʹͲ͏ࢥ͍·͔ͨ͠ʁ ݸਓతʹ͜ΕΒͷػೳΛ࠷ॳʹݟͨ࣌ʮѻ͏ͷ͕େͦ͠͏ʯͱࢥͬͨ
͜ͷ2ͭͷػೳΛݟͨ࣌ʹͲ͏ࢥ͍·͔ͨ͠ʁ ݸਓతʹ͜ΕΒͷػೳΛ࠷ॳʹݟͨ࣌ʮѻ͏ͷ͕େͦ͠͏ʯͱࢥͬͨ
͜ͷ2ͭͷػೳΛݟͨ࣌ʹͲ͏ࢥ͍·͔ͨ͠ʁ ݸਓతʹ͜ΕΒͷػೳΛ࠷ॳʹݟͨ࣌ʮѻ͏ͷ͕େͦ͠͏ʯͱࢥͬͨ
͜ͷ2ͭͷػೳΛݟͨ࣌ʹͲ͏ࢥ͍·͔ͨ͠ʁ makeSharedContext() ͷ͍ํ͕؊ʹͳΔ mockαʔόͱ௨৴͢Δʁ → PreviewͰͦ͜·Ͱ͢Δͷ͔ʁ ݸਓతʹ͜ΕΒͷػೳΛ࠷ॳʹݟͨ࣌ʮѻ͏ͷ͕େͦ͠͏ʯͱࢥͬͨ
PreviewModifier ͱ @PreviewableΛ׆ ༻ͨ͠ޮతͳϓϨϏϡʔํ๏ͷߟ
લఏͱͳΔViewͷ࡞ SNSͷλΠϜϥΠϯΛߟ͑Δ
લఏͱͳΔViewͷ࡞ SNSͷλΠϜϥΠϯΛߟ͑Δ ߘΛද͢ߏମΛఆٛ
લఏͱͳΔViewͷ࡞ SNSͷλΠϜϥΠϯΛߟ͑Δ ViewΛఆٛ [Post] Λ࣋ͪ body Ͱར༻
લఏͱͳΔViewͷ࡞
લఏͱͳΔViewͷ࡞
લఏͱͳΔViewͷ࡞ PreviewͰͬͱද͍ࣔͤͨ͞ʂ
લఏͱͳΔViewͷ࡞
લఏͱͳΔViewͷ࡞
લఏͱͳΔViewͷ࡞
લఏͱͳΔViewͷ࡞ ಡΈࠐΈ࣌ͷ Placeholder େৎ͔ͳʁ ໊લ͘ͳͬͨ࣌େৎ͔ͳʁ վߦ͞ΕͨΒେৎ͔ͳʁӳޠɾֆจࣈͷ࣌ େৎ͔ͳ ͍͍Ͷͷ͕ଟ͍࣌େৎ͔ͳ 0݅ͷ࣌ඇදࣔʹͳΔ͔ͳʁ
લఏͱͳΔViewͷ࡞ ඞཁͳύλʔϯͷ Post ΛՃ͢Ε ෳύλʔϯͷ Preview Մೳ ͔͠͠ӈਤͷΑ͏ʹ͔ͳΓݟͮΒ͘ͳΔ
લఏͱͳΔViewͷ࡞ ඞཁͳύλʔϯͷ Post ΛՃ͢Ε ෳύλʔϯͷ Preview Մೳ ͔͠͠ӈਤͷΑ͏ʹ͔ͳΓݟͮΒ͘ͳΔ @Previewable
PreviewModi fi er Λར༻͠ ղܾ͢Δ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ 1. JSONϑΝΠϧΛ࡞͠ɺඞཁͳσʔλΛՃ͢Δ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ 1. JSONϑΝΠϧΛ࡞͠ɺඞཁͳσʔλΛՃ͢Δ 1. ʢࠓճ ChatGPT Λར༻ͯ͠࡞ʣ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ 1. JSONϑΝΠϧΛ࡞͠ɺඞཁͳσʔλΛՃ͢Δ 1. ʢࠓճ ChatGPT Λར༻ͯ͠࡞ʣ
2. ʢ࡞͠Ճ͢Δ͚ͩͳͷͰׂѪʣ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ 1. JSONϑΝΠϧΛ࡞͠ɺඞཁͳσʔλΛՃ͢Δ 1. ʢࠓճ ChatGPT Λར༻ͯ͠࡞ʣ
2. ʢ࡞͠Ճ͢Δ͚ͩͳͷͰׂѪʣ 2. JSONϑΝΠϧΛಡΈࠐΈ decode ͠ Preview ʹೖ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ let posts: [Post] ͕ @Environment Ͱͳ͍߹
@Previewable Λར༻͢Δͱྑͦ͞͏
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ .task {} ͘͠ .onAppear {} Λ
ར༻ͦ͠ͷதͰಡΈࠐΈΛߦ͏
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ .task {} ͘͠ .onAppear {} Λ
ར༻ͦ͠ͷதͰಡΈࠐΈΛߦ͏ decode ͕ޭͨ͠Βɺposts ʹೖ ͢Δ
.task {} ͘͠ .onAppear {} Λ ར༻ͦ͠ͷதͰಡΈࠐΈΛߦ͏ decode ͕ޭͨ͠Βɺposts ʹೖ
͢Δ ෳͷύλʔϯͰ Preview ͕Մೳʹͳͬͨ 🎉
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ let posts: [Post] ͕ @Environment Ͱ͋Δ߹
PreviewModi fi er Λར༻͢Δͱྑͦ͞͏
@Previewable PreviewModifier Λར༻͠ղܾ͢Δ
None
None
·ͱΊ
·ͱΊ Xcode 16͔ΒPreviewModi fi er ͱ @Previewable ͕Ճ͞Εͨ ͜ΕΒΛར༻͢Δ͜ͱͰ Preview
ͷମݧ͕ΑΓ্͢Δ JSONϑΝΠϧΛར༻͠ΤϯςΟςΟΛೖ͢Δ͜ͱͰগ͠ͷίʔυͰଟྔͷύλʔϯΛ Preview Ͱ֬ೝ͢Δ͜ͱ͕Մೳ
͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ