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

Поделиться
HTML-код
  • Опубликовано: 6 окт 2024

Комментарии • 44

  • @nileshjdarji
    @nileshjdarji 2 месяца назад

    Nice way you showed us to add default data at app launch. Thank you.

  • @chezchezchezchez
    @chezchezchezchez 2 месяца назад

    You are a lifesaver dude!
    This solved my whole problem!

  • @tech_ch1211
    @tech_ch1211 Год назад +2

    Here we have some really helpful stuff, appreciated Tunds 🙆🏻‍♀

    • @tundsdev
      @tundsdev  8 месяцев назад

      Glad you enjoy it my man

  • @dmitrygolovin8066
    @dmitrygolovin8066 Год назад +1

    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 👌🏾

  • @SiamakAshrafi
    @SiamakAshrafi Год назад +1

    Great content !!! Thanks 🙏

    • @tundsdev
      @tundsdev  Год назад

      Thanks, glad you enjoyed it 👌🏾

  • @corey4139
    @corey4139 Год назад +2

    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  Год назад +1

      I have a vid planned to show this off 👌🏾

  • @Ride8715
    @Ride8715 Год назад +1

    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  Год назад +1

      Hey man, glad you enjoyed it. Funnily enough this is the next vid in this course which will come out on Sun 👀

  • @Alan-uc4pf
    @Alan-uc4pf Год назад

    yours videos are awesome, with good examples😂

    • @tundsdev
      @tundsdev  Год назад

      Glad you like em 👌🏾

  • @PaulSmithGainesville
    @PaulSmithGainesville 4 месяца назад

    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?

  • @holycrosscv
    @holycrosscv Год назад +1

    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  Год назад +1

      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 2 месяца назад

      anytime you have a try you can just stick in a do catch with a fatalError in the catch

  • @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  Год назад +1

      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 👌🏾

  • @sxmiotb2834
    @sxmiotb2834 Год назад +1

    Good stuff

  • @DefeatOG
    @DefeatOG 8 месяцев назад

    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?

  • @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 👀

  • @NICK4LIFE11
    @NICK4LIFE11 Месяц назад

    Is there a reason you used actor ItemContainer but in the preview lesson you just used a struct?

  • @lfan_tv
    @lfan_tv 4 месяца назад

    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?

  • @milanlabus1582
    @milanlabus1582 2 месяца назад

    What if you had a model thats unrelated to the other models how would you specify that modelContainer

  • @finchicoph
    @finchicoph 8 месяцев назад

    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  8 месяцев назад

      👋🏾 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

  • @grin_phi
    @grin_phi 8 месяцев назад

    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  8 месяцев назад +1

      You should check out my cloudkit vid that’s coming out pretty soon, that will cover this 👌🏾

    • @grin_phi
      @grin_phi 8 месяцев назад

      @@tundsdev cant wait - any idea when?!

    • @tundsdev
      @tundsdev  8 месяцев назад

      @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  Год назад +1

      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 Год назад +1

      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 🫂