How To Preload Data Into SwiftData ModelContainer ⚡️ | SwiftData Tutorial | #5

  Рет қаралды 5,218

tundsdev

tundsdev

Күн бұрын

Пікірлер: 44
@nileshjdarji
@nileshjdarji 4 ай бұрын
Nice way you showed us to add default data at app launch. Thank you.
@tech_ch1211
@tech_ch1211 Жыл бұрын
Here we have some really helpful stuff, appreciated Tunds 🙆🏻‍♀
@tundsdev
@tundsdev 10 ай бұрын
Glad you enjoy it my man
@corey4139
@corey4139 Жыл бұрын
Nice set of videos, thanks. Is it possible to pre-load data with a relationship? In your example can you import a to do that already has a category assigned?
@tundsdev
@tundsdev Жыл бұрын
I have a vid planned to show this off 👌🏾
@chezchezchezchez
@chezchezchezchez 4 ай бұрын
You are a lifesaver dude! This solved my whole problem!
@Ride8715
@Ride8715 Жыл бұрын
Great work tunds! My question is how would you do this to have some preloaded toDos? Would you have to create the extension on the toDoItem and then init each one?
@tundsdev
@tundsdev Жыл бұрын
Hey man, glad you enjoyed it. Funnily enough this is the next vid in this course which will come out on Sun 👀
@SiamakAshrafi
@SiamakAshrafi Жыл бұрын
Great content !!! Thanks 🙏
@tundsdev
@tundsdev Жыл бұрын
Thanks, glad you enjoyed it 👌🏾
@DefeatOG
@DefeatOG 10 ай бұрын
Great video! I have a question. My data preloads correctly, however now when I go to make a new "category" it does not save. If I delete a default category it will update and remove it but it seems like anything outside of the default data now does not get saved. It did before this, and if I don't use the ItemsContainer and just do it like before then everything works fine. Any idea?
@PaulSmithGainesville
@PaulSmithGainesville 6 ай бұрын
This video let me to you and I’m subscribed and plan to watch several. Great job on these!! I am new to SwiftData and this video helped me realize that I can create a class and initiate in App and inject it into the views. But I cannot figure out how to create a reference to the ItemsContainer outside a View. In my app, I need to call an API and pass JSON, but can’t get to the SwiftData model to create it within my class that calls the API. Have you covered this in any of your videos?
@Alan-uc4pf
@Alan-uc4pf Жыл бұрын
yours videos are awesome, with good examples😂
@tundsdev
@tundsdev Жыл бұрын
Glad you like em 👌🏾
@holycrosscv
@holycrosscv Жыл бұрын
This is really well done! Thanks so much for this great instruction. I am stuck trying to safely unwrap the container. Is there a way to return a default ModelContainer? Thanks!
@tundsdev
@tundsdev Жыл бұрын
Thanks & not that I know of, I think in this scenario its okay to force unwrap tbh 👌🏾
@holycrosscv
@holycrosscv Жыл бұрын
Have you tried adding Cloudkit with SwiftData? I get several errors when I add the framework. Curious what you are seeing. Thanks.
@milanlabus1582
@milanlabus1582 4 ай бұрын
anytime you have a try you can just stick in a do catch with a fatalError in the catch
@dmitrygolovin8066
@dmitrygolovin8066 Жыл бұрын
Great stuff! Would be cool to see repeatable daily, weekly, monthly, yearly tasks.
@tundsdev
@tundsdev Жыл бұрын
That’s going to be the plan in my paid course 👌🏾
@AliouSARR
@AliouSARR Жыл бұрын
Great video. I have a question can we use switData in a UIKit project ? Thanks
@tundsdev
@tundsdev Жыл бұрын
Yh you should be able too, you just can’t use the SwiftUI property wrappers instead you’d have to use fetch descriptors to fetch content etc. Maybe i’ll do a vid on it 👀
@sxmiotb2834
@sxmiotb2834 Жыл бұрын
Good stuff
@tundsdev
@tundsdev Жыл бұрын
Glad you enjoyed
@NormNorris
@NormNorris Жыл бұрын
Very good series of videos. Pre-filling a small amount of data works great. What about when you have a large json file of data you would like to pre-fill to SwiftData. Obviously this works but the app sits with a blank screen while this happens. Thoughts on how to show some sort of progress view? Challenging because you don't use .onAppear or .task in the ContentView where one could display a progress view.
@tundsdev
@tundsdev Жыл бұрын
I would look at moving this to a seperate context that isn’t bound to the view or if you want to wait for these items to be inserted then i would use the overlay modifier and have your view listen to a prop that tells you when its started and/or finished. Like a spinner with an API call.
@cloftis130
@cloftis130 Жыл бұрын
As always nice work. I wonder if you could set this up based on a query instead of a boolean. If the query/fetch returned empty, you could then prepopulate with categories. Thanks for the great video and education.
@tundsdev
@tundsdev Жыл бұрын
Thanks and you could do this. The only problem with this approach is that if your persistent storage is ever empty again. Then you’d be prefilling it multiple times. Using this flag via appstorage prevents that and only allows you to fill the storage once 👌🏾
@lfan_tv
@lfan_tv 6 ай бұрын
Hi Sir, what if i use this method to store the data, for the next version of my app, i want to add more preload category, how can I do it?
@NICK4LIFE11
@NICK4LIFE11 3 ай бұрын
Is there a reason you used actor ItemContainer but in the preview lesson you just used a struct?
@milanlabus1582
@milanlabus1582 4 ай бұрын
What if you had a model thats unrelated to the other models how would you specify that modelContainer
@finchicoph
@finchicoph 9 ай бұрын
How about pre-populating SwiftData with a huge data from an sql file? Checking on the docs I don't think SwiftData can do it out-of-the-box. How would you suggest to do it? Use Core Data?
@tundsdev
@tundsdev 9 ай бұрын
👋🏾 I suggest you watch this, you’d need to read the file & then import data on a backgroud thread. SwiftData Background Tasks: Massively Improve Your Apps Performance | SwiftData Tutorial | #12 kzbin.info/www/bejne/eGSthJqZjc-mgpo
@grin_phi
@grin_phi 10 ай бұрын
Great video Tunds. Really helped me. I'm now working on making the once only set up (i.e. create categories) work across multiple devices. Thinking of turning the @appstorage firstRun property into a ubiquitous key value pair. Any tips?
@tundsdev
@tundsdev 10 ай бұрын
You should check out my cloudkit vid that’s coming out pretty soon, that will cover this 👌🏾
@grin_phi
@grin_phi 10 ай бұрын
@@tundsdev cant wait - any idea when?!
@tundsdev
@tundsdev 10 ай бұрын
@grin_phi 11th of Feb 🥳
@holycrosscv
@holycrosscv Жыл бұрын
Beta 8 errors when it tires to create the ModelContainer. "Cannot convert value of type 'ModelConfiguration' to expected argument type 'any PersistentModel.Type'" Same error for schema. Any clue what is going on? Thanks!
@tundsdev
@tundsdev Жыл бұрын
Hey so there is a change you need to make to the relationship macro, it needs to be updated to this below. @Relationship(deleteRule: .nullify, inverse: \Category.items) But other than that everything else should build just fine/normally.
@osuaya
@osuaya Жыл бұрын
Hi. I am creating an application (code beta 15.8), without any type of relationship and it keeps showing me the same error. "Cannot convert value of type 'ModelConfiguration' to expected argument type 'any PersistentModel.Type'"@@tundsdev
@tundsdev
@tundsdev Жыл бұрын
Hi, is there a specific timestamp in the video that is causing you to see this error? I have the code here on my machine and really can’t reproduce it so i’m trying to see where the issue may be. Can you also check out my repo and the folder here to see if you can find any differences too github.com/tunds/youtube-content-2023/tree/main/How%20To%20Preload%20Relationships%20Into%20SwiftData%20ModelContainer%20⚡%EF%B8%8F%20%7C%20SwiftData%20Tutorial/Source%20Code
@osuaya
@osuaya Жыл бұрын
I have found the solution: you just have to add the word configurations. let container = try! ModelContainer(for: schema, configurations: configuration)
@tundsdev
@tundsdev Жыл бұрын
Glad you figured it out 🫂
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 91 МЛН
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 7 МЛН
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,6 МЛН
How To Use SwiftData with Preview | SwiftData Tutorial | #10
26:16
SwiftData Debugging The Easy Way | SwiftData Tutorial | #11
14:03
SwiftData Basics in 15 minutes
15:18
CodeWithChris
Рет қаралды 51 М.
Coding a FULL App with AI (You Won't Believe This)
15:19
Creator Magic
Рет қаралды 228 М.