Intro to SwiftData - Model, Container, Fetch, Create, Update & Delete

  Переглядів 46,467

Sean Allen

Sean Allen

День тому

Go to squarespace.com/seanallen to save 10% off your first purchase of a website or domain using code SEANALLEN.
This is an introduction to SwiftData new in iOS 17 and macOS Sonoma. SwiftData was introduced at WWDC 2023 and is the successor to Core Data. SwiftData is a way to persist your app's data locally on device or in iCloud to sync between devices. This video introduces you to the basic concepts like @Model, containers, context, fetch, create, update, and delete.
My iOS Dev Courses:
seanallen.teachable.com/
WWDC 2023 -Model your schema with SwiftData:
developer.apple.com/videos/pl...
X (Twitter):
Sean Allen - / seanallen_dev
Hired.com:
hired.com/x/1n01g
Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):
Paul Hudson's Hacking With Swift:
gumroad.com/a/762098803
Donny Wals - Combine:
gumroad.com/a/909014131
Mark Moeyken’s SwiftUI Books:
www.bigmountainstudio.com/swiftui-views-book/fzc51
Objc.io Books (Thinking in SwiftUI & Advanced Swift):
gumroad.com/a/656585843
Timestamps:
0:00 - What is SwiftData?
1:18 - Create Project & Model (@Model)
5:35 - Create & Explain Container (2 ways to do it)
8:42 - Separate Container Object (Configurations)
12:03 - UI Walkthrough
14:29 - Create Expense Items
17:33 - Fetch Expense Items (@Query)
18:39 - Delete Expense Items
20:20 - Update Expense Item
24:52 - Query Predicates (Filter Results)
#swift #softwaredeveloper #iosdeveloper

КОМЕНТАРІ: 124
@seanallen
@seanallen 7 місяців тому
Learn more with my iOS Developer courses at seanallen.teachable.com
@parthpatel7461
@parthpatel7461 4 дні тому
Crystal clear explanation
@seanallen
@seanallen 3 дні тому
Glad you liked it!
@Greg-du
@Greg-du 4 дні тому
absolutely clear in the essential. the best teacher ever 👍 regards from France
@VTivan
@VTivan 7 місяців тому
Great video, as usual. Would be great a part 2 explaining the iCloud sync with SwiftData
@TVsBen
@TVsBen 7 місяців тому
Yes I would love part 2! I have CloudKit enabled on a SwitData project but I'm not understanding how to get it to sync.
@seanallen
@seanallen 7 місяців тому
More Swift Data videos in the future for sure. No promises on when, but there's a few on my to-do list.
@peerview
@peerview 7 місяців тому
wow! that's a great video, yeah give 30 videos please. Would be great one about video or media in general? how to persist it ( i know, probably that's 50 videos long too XD)
@seanallen
@seanallen 7 місяців тому
Haha, yeah. SwiftData is a huge topic that will continue to grow as Apple builds upon this initial version.
@ridholmes
@ridholmes 7 місяців тому
Thank you!
@bradleygilmore
@bradleygilmore 5 місяців тому
This was by far the best SwiftData video I've seen. Thank you!
@satoriappdev
@satoriappdev 4 місяці тому
Honestly, what a fantastic video. Clear helpful, and patient. Learned so much of the basics without diverting too much into wild syntax and hard to comprehend coding. Really great work on this video it's perfect!
@SaschaBuerk
@SaschaBuerk 3 місяці тому
Just started to dip my toes into iOS development and I wasn't aware how recent some of the things I try to use are. It's so hard to find guides. So this is perfect.
@seanallen
@seanallen 3 місяці тому
Happy to help 👍
@thetutorialdoctor
@thetutorialdoctor 4 місяці тому
To the point, not overdone, not underdone and concise and clear. Great tutorial. This has everything you need to know to get started working with SwiftUI and SwiftData with good explanations
@mkboy5596
@mkboy5596 7 місяців тому
thank you bro clear and smooth 🥰
@seanallen
@seanallen 7 місяців тому
You're welcome!
@AndrewDChristie
@AndrewDChristie 4 місяці тому
I've been watching for a while, I like Sean's teaching style - he has a great way of making complex concepts simple and understandable
@seanallen
@seanallen 4 місяці тому
I appreciate the long-time support, Andrew!
@vinidotco
@vinidotco 7 місяців тому
A+ content for sure, thanks Sean,
@seanallen
@seanallen 6 місяців тому
I appreciate that! Glad you liked it.
@ArneGockeln
@ArneGockeln 7 місяців тому
Very helpful! Thanks for sharing it!
@seanallen
@seanallen 6 місяців тому
Happy to help!
@denisfok1699
@denisfok1699 7 місяців тому
Thanks for the intro, that is extremely useful.
@seanallen
@seanallen 7 місяців тому
Glad it was helpful!
@kuldar
@kuldar 7 місяців тому
You have such a clear way of explaining concepts. Great work! Looking forward to the new course!
@seanallen
@seanallen 6 місяців тому
I appreciate the kind words, Kuldar!
@patgoo2
@patgoo2 7 місяців тому
Great, that covers a lot of information with swiftData and looking forward to your next video.
@seanallen
@seanallen 6 місяців тому
Glad you liked it!
@yousifkurdy4778
@yousifkurdy4778 7 місяців тому
Exactly what i wanted!
@seanallen
@seanallen 7 місяців тому
Hope ya like it!
@TheEmperorXavier
@TheEmperorXavier 7 місяців тому
I just discovered your channel and I’m watching your Swift UI Fundamentals Video. You keep dropping these fire videos which is helping me understand SwiftUI a lot. Thanks soo much and I greatly appreciate your valuable work.
@seanallen
@seanallen 6 місяців тому
Welcome to the channel! Glad you're enjoying the content :)
@DD-hh3sp
@DD-hh3sp 2 місяці тому
Love your style, Sean. You explain things well and make it understand. Thanks!
@DD-hh3sp
@DD-hh3sp 2 місяці тому
*understandable.
@seanallen
@seanallen 2 місяці тому
I appreciate that! Glad you like my teaching style.
@naeem3dful
@naeem3dful 7 місяців тому
Hey Sean, I just wanted to let you know how much I appreciate the way you present and explain new things. Your videos make complex topics seem so simple and understandable. It's clear that you have a talent for breaking things down. Thanks for making data storage seem so much easier in your beautiful way. Keep up the fantastic work!
@seanallen
@seanallen 6 місяців тому
I really appreciate the kind words and it's motivation to keep going 💪. Glad you're enjoying the content!
@chezchezchezchez
@chezchezchezchez 7 місяців тому
Omg. I asked, and I received!! Thanks, Sean!
@seanallen
@seanallen 6 місяців тому
Happy to help!
@allenwixted1992
@allenwixted1992 6 місяців тому
Sean! Back working on an iOS app and this is exactly what I needed. Haven’t coded since we spoke probably like 5 years ago when ARKit first came out. Excited to put it to use
@seanallen
@seanallen 6 місяців тому
Hey Allen! Welcome back. 👋
@michaelbouril5278
@michaelbouril5278 Місяць тому
This is just incredible, your level of mastery and ability to step through each portion with great clarity is unheard of!
@seanallen
@seanallen Місяць тому
I appreciate the kind words and glad you liked the video!
@sandeep_hegde
@sandeep_hegde 4 місяці тому
Your comment for the UKposts video on Swift Data could be phrased like this: I've watched several tutorials on SwiftData, but this one stands out as the best introduction to the topic so far. Sean has a unique talent for simplifying complex concepts and making them easily understandable. Thanks Sean. 🙌"
@user-jl3xp5yp6d
@user-jl3xp5yp6d 7 місяців тому
Good lesson. Thanks
@seanallen
@seanallen 6 місяців тому
Happy to help
@chrisrudy1969
@chrisrudy1969 Місяць тому
Thanks for the video!
@seanallen
@seanallen Місяць тому
Happy to help!
@ondrejrohon5696
@ondrejrohon5696 7 місяців тому
I did a bit of iOS development when Swift was brand new and it's incredible how far i went.. so much simpler nowadays. I was thinking about side project with nice offline functionality and I though about CoreData and how complex it is. This is such a good news to see there is beautiful new "SwiftUI" way how to do it. Thanks so much for this clear introduction! :)
@seanallen
@seanallen 6 місяців тому
Yes... this will be a huge improvement over Core Data.
@ahmedhamadto8756
@ahmedhamadto8756 4 місяці тому
Hi Sean, I've been watching some videos on your channel, and your method of presentation is excellent and easy to follow, I'm completely new to iOS development and was wondering if you have a video or tutorial that has a complete beginners guide?
@pavloma6836
@pavloma6836 5 місяців тому
Man... your explanation is top notch! You know where to put accents! Very well done 👍
@seanallen
@seanallen 5 місяців тому
Thanks! Glad you like my teaching style.
@timotejmatlak4625
@timotejmatlak4625 Місяць тому
Thank you Sean, you are the best teacher with the best content ever :)
@seanallen
@seanallen Місяць тому
Thanks for the kind words :)
@dgeneration
@dgeneration 7 місяців тому
Can you make a video showing how to implement swiftdata outside of a view? I’d also like to see fetch descriptors explained if possible.
@torfeuzarre
@torfeuzarre 7 місяців тому
Thanks Sean. Great tutorial as usual 😊 As a beginner it looks far easier to begin than Core Data 😅
@seanallen
@seanallen 6 місяців тому
Yes... it's much easier. It needs another year or two to mature, but it's a great start and clearly the future.
@doublepee5752
@doublepee5752 6 місяців тому
That was super useful thanks.
@seanallen
@seanallen 6 місяців тому
Glad to hear it!
@doublepee5752
@doublepee5752 6 місяців тому
Are you on Threads,@@seanallen ? I'd like to follow you. `
@HusamSokagi
@HusamSokagi 7 місяців тому
Great content! Very useful but as everything that introduced newly, to use them daily, we need to wait until iOS 17 is used more.
@seanallen
@seanallen 6 місяців тому
Yes. And it's probably needs another year or two to be fully ready for complex projects.
@ishool108
@ishool108 5 місяців тому
Thanks for the video. Two questions: - How do you work with related one-to-one and one-to-many models? - How to bring the logic of working with storage into ViewModel?
@Bankai3474
@Bankai3474 7 місяців тому
Great video, I've been working on an app with SwiftData since it was announced while doing the #100DaysOfSwiftUI challenge. You were wise to wait till now before making a video because there were some bugs when you had custom types and enums haha. Anyways, thanks for the example because now I can change my edit view, Apple's example app of updating an existing SwiftData object isn't like this so now I can clean up my code a bit.
@seanallen
@seanallen 6 місяців тому
I agree. This is definitely a great start for SwiftData, but it needs another year or two to mature.
@Michael-Martell
@Michael-Martell Місяць тому
Incredible video man! First time seeing anything from your channel! Been slamming my keyboard trying to get through UI mismatching and out of date CoreData tutorials. I would love to purchase a SwiftData course if you have one. Would you post on Udemy maybe?
@seanallen
@seanallen Місяць тому
Glad you liked it! I don't have a Swift Data course (yet) because it's pretty new and I expect a lot of updates and changes with iOS 18 this year.
@mattross9992
@mattross9992 4 місяці тому
Do you have a video on how to use swift data and preload the database and the data?
@jacobwoods1032
@jacobwoods1032 7 місяців тому
Could you make a video about becoming a freelance app dev?
@ayberkmogol
@ayberkmogol 7 місяців тому
@bharned3
@bharned3 3 місяці тому
Thanks I have been enjoying your videos. Is this one available to grab as a starter
@seanallen
@seanallen 3 місяці тому
I don't have starter projects, however you can grab the completed source code at seanallen.teachable.com/p/source-code-youtube-videos
@chesterman18g
@chesterman18g 7 місяців тому
Container-Context in SwiftData is really a mirror of an CoreData Persistent store and ManagedObjectContext with sugar of autosave (?).
@seanallen
@seanallen 6 місяців тому
Yup. That's it.
@xtu373
@xtu373 7 місяців тому
Please make some vidoes of data structures and algorithms in Swift
@seanallen
@seanallen 7 місяців тому
That's out of my area of expertise. I haven't interviewed for a job in a long time and that's the only time I ever used or studied that topic.
@moamberraza7658
@moamberraza7658 7 місяців тому
in case where you are handling with multi model how we are going to identify which is getting triggered in view. just a little confusion here as i am a basic learner.
@anudeepananth
@anudeepananth 3 місяці тому
How do we perform CRUD outside the view, example periodically check for new data from the server, download it using background tasks but now it needs to be persisted to local database
@unthinkabilities
@unthinkabilities 6 місяців тому
Awesome video, SwiftData looks really good. The only thing I’m wondering is: What happens to an Expense when we assign it to the ExpenseToEdit variable and then dismiss the edit sheet? Does that Expense just keep sitting in the variable until we assign to it a different Expense (at which point I assume the sheet would trigger again)? Or does Swift automatically set the value to null again after we dismiss the sheet?
@seanallen
@seanallen 6 місяців тому
It will hold the value until we assign it a different one (at which point would trigger the sheet again with the new information)
@ManojAP
@ManojAP 6 місяців тому
can you tell me how I connect sql based db to swift data.... video is useful. thank you
@OttoFaerber
@OttoFaerber 7 місяців тому
What is with Dynamic Filter
@gmjelle
@gmjelle 6 місяців тому
Hi Sean, really informative video. Is there a way to get data from a network request and transform the json straight into a swiftdata model with Codable?
@seanallen
@seanallen 6 місяців тому
Yes... in SwiftData your models are the same models you would use in normal Swift code.
@nitramluap
@nitramluap 7 місяців тому
I need to be able to migrate my CoreData app to SwiftData but it's just not there yet... CoreData is still WAY more sophisticated, particularly for large complex databases with lots of > relationships, etc. Fingers crossed they'll make it possible in the next year....
@seanallen
@seanallen 6 місяців тому
Agreed... give SwiftData another couple years. It's clearly the future, but not quite there yet for complex projects.
@Uz_Mobile_Developer
@Uz_Mobile_Developer 7 місяців тому
Thanks for video. I think IOS development very easy than Android development. This video was very helpful
@seanallen
@seanallen 6 місяців тому
Glad it helped!
@josep-rudo
@josep-rudo 24 дні тому
Hi Sean! Thanks for your SwiftUI videos, for all of them. Are really helpful!,. Please, Can you share your Xcode theme? Thanks in advance 🫶🏻
@seanallen
@seanallen 24 дні тому
Happy to help. The theme is called Midnight. it's a default one in Xcode. The only thing I changed was the color of the comments. I made them grey.
@andymorato7588
@andymorato7588 4 місяці тому
Does anyone know if there is a way to query based on a State var? Say there is a button where the user can set the month with the intention of viewing every expense pertaining to just that month. I don't think we can just set the month as a state var and use it in the Query filter
@modhi210
@modhi210 5 місяців тому
what did you mean by ExpenseCell ?
@sreekanthzyou
@sreekanthzyou 4 місяці тому
want to create SwiftData in a Framework not in Host App. where do we specify the model container?
@diegomesquitamendes8210
@diegomesquitamendes8210 7 місяців тому
How can I use the context outside swiftUI? Like if I want to manage in a different class an Object stored in a context
@seanallen
@seanallen 6 місяців тому
In the video I show you how to create a container object. Once you have that object you can use it outside the view hierarchy (like a SwiftDataManage singleton for example).
@DragonByte79
@DragonByte79 3 місяці тому
Does anyone know if I have to care about unique constraints? Do I have to check if it exists before inserting it? Currently, it is working. It won't add another one. Is SwiftData handling it?
@piteke100
@piteke100 3 місяці тому
Hi, I’m continuing to study SwiftData by repeating all the tutorials but I can’t understand one thing: I have to create an app with a default list (which therefore no data needs to be added) and this list is contained in a toggle. How do I make only the toggle state persistent?
@denisk3852
@denisk3852 7 місяців тому
How about sharing data between an app and widgets?
@seanallen
@seanallen 7 місяців тому
Use an app group and put that ID in the container configuration parameter.
@morgancooledge3557
@morgancooledge3557 3 місяці тому
New to SwiftU here. Is it SwiftUI best practice to keep the .sheet views code inside the same view as the content view or better to have them in their separate views? So instead of 1 view you would have 3, if that makes sense.
@seanallen
@seanallen 3 місяці тому
I'm not sure I follow what you mean. Do you mean within the same file, or within the actual View?
@morgancooledge3557
@morgancooledge3557 3 місяці тому
@@seanallen Sorry I think I meant file.
@bharned3
@bharned3 2 місяці тому
Anyone found a way to back up the data. Not sync it for multiple devices, but create a backup file of the data to iCloud or dropbox, then restore from that file if needed.
@Mater-code
@Mater-code 7 місяців тому
can you talk about vision os?
@seanallen
@seanallen 6 місяців тому
I have an overview video here - ukposts.info/have/v-deo/jl2efX-arY-jyWQ.htmlsi=dpjgdJwFYlQQ2o65
@septimir5278
@septimir5278 3 місяці тому
If @Query results change, will the view invalidate like with @State and re-render?
@seanallen
@seanallen 3 місяці тому
Yes, that's how it should work.
@joshuarileymagic
@joshuarileymagic 4 місяці тому
This really is amazing but it put me off using it atm because it's obviously only from iOS 17 & above, I'm using FMDB right now
@satoriappdev
@satoriappdev 7 місяців тому
Would you use this over Realm?
@seanallen
@seanallen 6 місяців тому
I've never used Realm before, so I can't give a valid opinion here.
@satoriappdev
@satoriappdev 6 місяців тому
okay, thanks!@@seanallen
@Jem-xu2jm
@Jem-xu2jm 6 місяців тому
please my friend make tutorial based on new swiftdata and swift ui, like recent ones, 10 hours each
@seanallen
@seanallen 5 місяців тому
Oh, just a casual 10 hour tutorial??
@HarutoPlay
@HarutoPlay Місяць тому
How can I save a dict?
@johnpatrickechavez1216
@johnpatrickechavez1216 4 місяці тому
is this only work in iOS 17?
@seanallen
@seanallen 4 місяці тому
Yes, this requires iOS 17 and above.
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
8. SwiftData   CloudKit
18:20
Stewart Lynch
Переглядів 4,3 тис.
Authentication is a developer nightmare
15:58
Tom Delalande
Переглядів 185
Swift Closures Explained
14:23
Sean Allen
Переглядів 56 тис.
Expert Advice to Learn iOS Dev & Swift FAST
1:04:52
Sean Allen
Переглядів 35 тис.
SwiftData Basics in 15 minutes
15:18
CodeWithChris
Переглядів 33 тис.
Your App Will Get Rejected | New Privacy Rules - 2024
11:26
Sean Allen
Переглядів 28 тис.
Big Tech AI Is A Lie
16:56
Tina Huang
Переглядів 51 тис.
Я Создал Новый Айфон!
0:59
FLV
Переглядів 1,8 млн
It's embarrassing how much I like this thing.
12:19
Linus Tech Tips
Переглядів 853 тис.