How to best use Core Data with SwiftUI 2.0 - MVVM - Unit test and working with the preview

Поділитися
Вставка
  • Опубліковано 21 сер 2024

КОМЕНТАРІ • 33

  • @tayloratheo
    @tayloratheo 2 роки тому +2

    How do I like this video a million times?

  • @coolcodingdad
    @coolcodingdad Рік тому +1

    Excellent video Karin! You helped me understand how to work with Core Data in SwiftUI and how to test it to the next level! Thank you so much! 😄👍

  • @keatsp
    @keatsp Рік тому +1

    AMAZING. I am a long time app developer with many apps that extensively implement CoreData. This is BY FAR the best tutorial I have ever seen and I have seen ALOT. I am immediately implementing most of this into my apps. Thank you so much.

  • @seccat
    @seccat 3 роки тому +1

    Thanks you solved my NSInternalInconsistencyException problem, in the first 3 minutes. I was save my persistence context too often.

    • @SwiftyPlace
      @SwiftyPlace  3 роки тому

      Excellent! Good to know that this is crucial information. I was already wondering why this topic is not talked more about.

  • @LeviM337
    @LeviM337 3 роки тому +5

    Wow god bless you! Thank you so much.

  • @garychen8185
    @garychen8185 3 роки тому +1

    I have been binging your videos on SwiftUI and I want to leave a comment to commend you for these excellent content.

  • @danielwatson6529
    @danielwatson6529 2 роки тому

    I think this is the one for me! watching in silence because i for got my head phones on the train. will nail this when i get home!!

  • @tayloratheo
    @tayloratheo 2 роки тому

    This has honestly help my cut down on 33% of the code I've been writing and it's only been a week since I watched the video. Thanks much!

  • @mhfs61
    @mhfs61 2 роки тому +2

    Hi Karin,
    Thank you for this video. It’s a confirmation of something I came across and I couldn’t fix, the way it was apparently supposed to be done.
    After trying to implement MVVM in the standard way (using CoreData and CloudKit) without having several issues, I finally came to the same solution you’re proposing. I still wasn’t sure whether it was the a good solution, though it worked. So again thank you for this confirmation.
    Furthermore I also use a temporary struct for each entity. That temporary struct is populated, when displaying the entity detail view. In the detail view I collect the changes made in the temporary struct and only save the changes when the save/update button is tapped. The save/update button is only activated when any change is made. When the save/update button is active and tapped, the entity is populated with the collected data from the temporary struct. This prevent the listview to display changes that where not persisted in the database (one of the several issue I came across.)

  • @fulviofagnani8395
    @fulviofagnani8395 3 роки тому +9

    Hi Karin! Very interesting adaptation of MVVM, especially when dealing with swiftui and core data. Is there somewhere to download this code example, this would be very useful. Thanks so much for these great tutorials!

    • @dmitriykhan2011
      @dmitriykhan2011 2 роки тому

      Not here. It's not a Stanford. But, you can download codes from Stanford lectures where she take ideas.

  • @HilaProdomo
    @HilaProdomo 3 роки тому

    Great video. I learned a lot about code structure with Core Data and SwiftUI.

  • @luisgomezreus732
    @luisgomezreus732 2 роки тому

    Very nice video. Thank you very much Karin.

  • @user-gr3kt8uk3c
    @user-gr3kt8uk3c 3 роки тому

    Thx for your work!

  • @consumer8592
    @consumer8592 3 роки тому

    You’re the best! Thanks a lot 🙏🏼

  • @arthurgeniere432
    @arthurgeniere432 2 роки тому

    amazing job, thx

  • @antonsergeyev2624
    @antonsergeyev2624 3 роки тому

    Thanks a lot!

  • @matthiasrudnick9888
    @matthiasrudnick9888 3 роки тому

    Thanks a lot.

  • @phongphong1986
    @phongphong1986 2 роки тому

    thank you for sharing

  • @jasperdunn
    @jasperdunn 3 роки тому

    Hey Karin, thanks again for the excellent explanations throughout your tutorials! Just wondering, how do you auto-format the code? is there a shortcut you're using?

    • @SwiftyPlace
      @SwiftyPlace  3 роки тому +1

      Good question! The keyboard shortcut is control + i
      You can also have a look at more shortcuts in this list peterfriese.dev/xcode-shortcuts/

  • @helloworld_sw
    @helloworld_sw 2 роки тому +2

    Please use dark mode in Xcode in future videos.

  • @MsEva112
    @MsEva112 2 роки тому +1

    how you solved the problem in Unit Test part is not clear, your code is changed suddenly. I am getting the a run time error too. Do you know what the problem is and how to solve ? Did you change the static empty var in Persistence file?

    • @notorioustofu3482
      @notorioustofu3482 2 роки тому

      First, she deleted both testing targets and create a new one (File>New>Target>Unit Testing Bundle). If you do the same and put the code in as it was originally, it throws errors on the PersistenceController variable. If you look at the code after her cut away, she's PersistenceController instance into the function itself. I'd try the code change before deleting the targets

  • @notorioustofu3482
    @notorioustofu3482 2 роки тому

    I found that if test_fetch method's `var item = Item(context: context)` is commented out, the test will throw false positives when setting the testing scheme to execute in random order and running all tests a few times. I assumed that since empty is held in memory, the item created in test_Add_Item is still in memory. Adding `addTeardownBlock { context.delete(item) }` at the end of test_Add_Item resolves the issue.

  • @achimreiske1964
    @achimreiske1964 2 роки тому

    Hi Karin, at first I have to thank you for your very good videos.
    To this video I have some questions. Maybe you can explain it to me.
    You have the functions to add and to delete Item(s). You have the delete func in the item extension and the add func in the view.
    Wouldn't it be better to have both in the same place? And you always have to call the PersistenceController.save method.
    Is it possible to have both functions inside the PersistenceController or in the ItemExtensiion and also call the save in there?
    Then you would have the addItem func in the view only like this:
    private func addItem() {
    withAnimation {
    _ = PersistenceController.shared.addItem()
    }
    }
    or
    private func addItem() {
    withAnimation {
    _ = Item.addItem(context: viewContext)
    }
    }
    Is there something that could go wrong if I do it in this way?

  • @danielwatson6529
    @danielwatson6529 2 роки тому

    Is there a way to have the @fetchrequest tucked away in the view model?

    • @SwiftyPlace
      @SwiftyPlace  2 роки тому +1

      That would be great. But when I tried it, my app crashed. I think the problem is that it need the NSManagedContext in the SwiftUI environment. The view model does not 'see' the view environment.

  • @yourgflikesit
    @yourgflikesit Рік тому +1

    How to do core data migrations though?