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
CoreDataからSwiftDataへの移行
Search
ムッチョ
November 16, 2023
1
18
CoreDataからSwiftDataへの移行
ムッチョ
November 16, 2023
Tweet
Share
More Decks by ムッチョ
See All by ムッチョ
Databaseのことを考えずにiOSアプリを作る ローカルデータベースを使うときの アーキテクチャ設計
musayazuju
1
71
Featured
See All Featured
Designing on Purpose - Digital PM Summit 2013
jponch
112
6.6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
275
13k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
228
16k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
358
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
71
14k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
247
20k
The Invisible Side of Design
smashingmag
294
50k
Docker and Python
trallard
36
2.8k
Clear Off the Table
cherdarchuk
87
310k
Fashionably flexible responsive web design (full day workshop)
malarkey
399
65k
Build your cross-platform service in a week with App Engine
jlugia
227
17k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
Transcript
CoreDataから SwiftDataへの移行
自己紹介 • ヤズジュ夢佐(ムッチョ) • iOSエンジニア • 11月1日にVoicy入社(2週間) • マッチングアプリ->オンライン英会話アプ リ->Voicy
Mucchoo Mucchooooo
個人開発もやってます! 英単語学習アプリ
SwiftDataとは • iOS17で登場 • CoreDataを使いやすくしたもの • SwiftUIと相性がいい CoreDataとは • 端末内にデータを保存できる
• CloudKitを使って複数の端末でデータを共有す ることも可能
移行の3Step 1.Schema (構造) 3.Model Context (CRUD処理) 2.Model Container (Persistence)
Schema 1. .xcdatamodeld fileを選択 2. Editor -> Create SwiftData Code
→
None
↑
Persistence
Model Container • アプリで使いたいModel Typeを全て指定 • WindowGroupにセットす るだけで、 @Environmentから model
contextにアクセス できる
NSManagedObjectContext - CRUD処理
Model Context • CRUD処理全般 • Save Call不要 ->自動保存されます
@Query • データ自動更新 • SwiftUI画面自動更新 • 配列のFilter, Sort操作が簡単 for SwiftUI
まとめ • SwiftDataをSwiftUIと合わせて使うことで データの扱いが楽になる • CoreDataからの移行も簡単!
ありがとうございました!