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?
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?
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?
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!
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.
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.
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.
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 👌🏾
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?
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 👀
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?
👋🏾 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 ruclips.net/video/B3JSgcXjsL8/видео.html
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?
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!
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.
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
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
I have found the solution: you just have to add the word configurations. let container = try! ModelContainer(for: schema, configurations: configuration)
Nice way you showed us to add default data at app launch. Thank you.
You are a lifesaver dude!
This solved my whole problem!
Here we have some really helpful stuff, appreciated Tunds 🙆🏻♀
Glad you enjoy it my man
Great stuff! Would be cool to see repeatable daily, weekly, monthly, yearly tasks.
That’s going to be the plan in my paid course 👌🏾
Great content !!! Thanks 🙏
Thanks, glad you enjoyed it 👌🏾
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?
I have a vid planned to show this off 👌🏾
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?
Hey man, glad you enjoyed it. Funnily enough this is the next vid in this course which will come out on Sun 👀
yours videos are awesome, with good examples😂
Glad you like em 👌🏾
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?
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!
Thanks & not that I know of, I think in this scenario its okay to force unwrap tbh 👌🏾
Have you tried adding Cloudkit with SwiftData? I get several errors when I add the framework. Curious what you are seeing.
Thanks.
anytime you have a try you can just stick in a do catch with a fatalError in the catch
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.
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.
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.
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 👌🏾
Good stuff
Glad you enjoyed
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?
Great video.
I have a question can we use switData in a UIKit project ?
Thanks
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 👀
Is there a reason you used actor ItemContainer but in the preview lesson you just used a struct?
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?
What if you had a model thats unrelated to the other models how would you specify that modelContainer
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?
👋🏾 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
ruclips.net/video/B3JSgcXjsL8/видео.html
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?
You should check out my cloudkit vid that’s coming out pretty soon, that will cover this 👌🏾
@@tundsdev cant wait - any idea when?!
@grin_phi 11th of Feb 🥳
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!
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.
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
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
I have found the solution: you just have to add the word configurations. let container = try! ModelContainer(for: schema, configurations: configuration)
Glad you figured it out 🫂