Core Data in SwiftUI Using MVVM Design Pattern

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

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

  • @0wang50
    @0wang50 2 года назад

    Thank you very much! This video solving the notion of viewmodel for me.

  • @WilfClegg
    @WilfClegg 2 года назад

    Mohammad, I found that my "title" textField input was intermittently being truncated (last character). So, to fix this problem, I added @Published to the title variable in the TaskListViewModel. Some of your viewers may be experiencing the same issue. This fixes it. Many thanks for the video, this is watershed code that can be used over and over in many Core Data applications.

  • @_sabot
    @_sabot 3 года назад +3

    First of all, very nice and clear presentation style 👍
    I like that you don’t do the actual core data stuff directly in your view model. What I don’t like though, is that you're putting everything inside this common CoreDataManager class. That might be because of this very basic example with only one entity, but if you want to teach a good architecture to beginners you should show directly something which is able to scale. If the app will grow with more views, view models and entities this CoreDataManager will get very big and messy soon. Other than that, I would recommend a reasonable architecture should separate the handling from the NSManagedObjectContext from it’s usage. You are also using the singleton pattern here in a way which I wouldn't recommend. For instance, there is no way to use a memory only persistence store if you want to write unit tests.
    What I would suggest:
    - Handle the NSManagedObjectContext in an own class similar to the one Xcode generates if you check CoreData while creating a new project. IMHO it’s okay to make this a singleton as long you use that only as the default parameter inside an init method.
    - Write separate classes for each entity (I call them Repositories) which abstract the CRUD operations and in which you inject the context.
    - Make these repositories each implement a protocol
    - The view model only knows the protocol of the repository
    With this architecture you can write tests for the repo with an memory only core data context and if you want to write tests also for the view model, you can replace the repo with a mock / dummy which doesn’t use core data at all.

    • @azamsharp
      @azamsharp  3 года назад +3

      Thanks for your comments. I am a believer is baby steps meaning taking small steps to a bigger solution and not overly complicating stuff from the beginning. In my last video, I put all the code in Views just to show how Core Data persistence work. In this video, I used MVVM pattern. As you mentioned our app is simple so a single CoreDataManager would be enough. As the app scale we can have functionality in the model which inherits from the BaseModel. I covered that in my Core Data course on Udemy.
      For Unit Tests, I would focus on domain level tests and then tests everything else using integration and acceptance tests.

    • @danielwatson6529
      @danielwatson6529 3 года назад

      is there a repo you could share that i could read to learn from with the implementation you are recommending

  • @MauricioChavesDias
    @MauricioChavesDias 2 года назад

    Thank you so much for this video. It helped me a lot to build an application for a job application. I just bought your course at Udemy! And I’m really interested to continue learning more about Core Data with you. I was thinking if you can create some videos building an app using Core Data plus API calls using MVVM on SwiftUI. Maybe explain as well about the folders created on MVVM architecture. Cheers

  • @ben.aka.bigben
    @ben.aka.bigben 2 года назад

    Very helpful Azam. thank you :)

  • @nurirfanpangestu3696
    @nurirfanpangestu3696 3 года назад

    so amazing sir, thank you so much

  • @OttoFaerber
    @OttoFaerber 3 года назад

    Great Video, ohne question, how do you this automatic insert Hstack?

  • @MoSaghafian
    @MoSaghafian 2 года назад

    Thank you

  • @amphortas1
    @amphortas1 2 года назад

    Thank you Mohammad Azam for this video. It explains a lot but unfortunately you don't provide all CRUD operations (for example, this video is missing how to edit existing tasks)

    • @azamsharp
      @azamsharp  2 года назад +1

      I may have some other videos on update functionality.

    • @amphortas1
      @amphortas1 2 года назад

      @@azamsharp Thank you! It will be nice to see.

    • @amphortas1
      @amphortas1 2 года назад

      @@azamsharp I have bought both your Udemy courses: "MVVM Design Pattern Using Swift in iOS" and "MVVM Design Pattern in SwiftUI", what the main difference between them? I love this approach and thank to MVVM + CoreData I have started to understand how to use Core Data also.
      When you will create a new video, please don't forget to show the moment when it's best to initialise the Core Data, for example, if the app will use the pre-populated data (for example, a list of English words with translation, or a list of available addresses, for a situation when the app works offline without access to internet, without loading data from any remote database, in some Udemy trainings you provides examples of projects which uses Firestore db from Firebase, but if to create the app which doesn't use any remote databases?)

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

    Hello Mohammad, thanks for the video. It's very helpful. I have a question though. Why do we have a deleteTask function in our view? Is it possible to move it anywhere else if we want our view cleaner, without any functions and such?

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

      deleteTask inside the View is not doing much. It is invoking the delete method on VM.
      PS: My views on using MVVM has evolved and I no longer recommend MVVM architecture for SwiftUI applications. I have written about it extensively on my website. www.azamsharp.com

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

      @@azamsharp Thanks for the answer! I will surely check out the article!

  • @abdouett3676
    @abdouett3676 3 года назад

    Thank you Azam for this powerful video!

    • @kristopherjoaquin2037
      @kristopherjoaquin2037 3 года назад

      A trick : watch movies at kaldrostream. I've been using them for watching lots of of movies recently.

    • @yousefreyansh3506
      @yousefreyansh3506 3 года назад

      @Kristopher Joaquin Definitely, have been watching on kaldrostream for since december myself =)

    • @xandercharlie3525
      @xandercharlie3525 3 года назад

      @Kristopher Joaquin yup, been watching on KaldroStream for years myself :)

  • @daliakm178
    @daliakm178 3 года назад

    Thank you, that was amazing

  • @yuridavellodalmagro4960
    @yuridavellodalmagro4960 3 года назад

    I need to do a Crud inside a Crud and pass the ID of the selected row, how do you recommend me to do that? is there anyway you could help me with that? if so how could I contact you

  • @judy8821
    @judy8821 3 года назад

    Nice

  • @hsksearch3
    @hsksearch3 3 года назад

    How to delete all rows in one time? Please help^^ thank you

  • @mathewcrovitz7867
    @mathewcrovitz7867 3 года назад

    Nice video. I wouldn't mind purchasing the UDEMY class, but, it's not showing the "introductory" cost. I'm not going to spend close to $100 for my "hobby". Do you have a link for the cost shown on this video, or, a discount code to get it at that price? Thanks!

    • @azamsharp
      @azamsharp  3 года назад

      Use this: www.udemy.com/course/core-data-in-ios/?couponCode=5991B32AA46122F868DF

  • @MrMichaelcaesario
    @MrMichaelcaesario 3 года назад

    Hi Azam! love love your videos! I learn so much from you. I want to ask you one thing about this video, I usually use core data with fetchrequest property wrapper and I saw it nowhere on this video, how can I sort the data with this technique? i have created one with a date its what I'm gonna use to sort the data on the foreach loop and now I just can't seem to figure it out how can I sort it without @fetchrequest

    • @azamsharp
      @azamsharp  3 года назад

      Check if it has sortDescriptors property. It it does not then use the old way.

  • @peterbien4049
    @peterbien4049 3 года назад

    why was the update function not shown in the video?

    • @azamsharp
      @azamsharp  3 года назад +1

      Here is the code for update: github.com/azamsharp/MoviesAppUpdate

    • @peterbien4049
      @peterbien4049 3 года назад

      @@azamsharp Thank you very much for your fast reply. This is exactly what I missed in your Tutorial „Core Data …“ in Udemy

  • @divakarreddy1040
    @divakarreddy1040 3 года назад

    not able to see CoreData in iOS course in udemy business

    • @azamsharp
      @azamsharp  3 года назад +1

      Maybe Udemy will add it in the future.

  • @rillieux1792
    @rillieux1792 3 года назад

    Great video, thank you. I have a question - in contrast to the `persistence.swift` file template Xcode generates for a SwiftUI CoreData SwiftUI life cycle app, your `CoreDataManager` is a class, instead of a struct. Is there a particular reason for this? I want to learn how to apply your solutions but in a template generated initially by Xcode. Is it fair to think of both those files as performing the same thing / role in the app? Thanks again for the video. We really need tutorials on SwiftUI+CoreData+MVVM and this is very helpful.

    • @azamsharp
      @azamsharp  3 года назад +1

      Struct is mainly used for value types but CoreDataManager is not really holding any values. It is more acting like a service hence Class.

    • @rillieux1792
      @rillieux1792 3 года назад

      @@azamsharp It's very nice to see such a quick response. : ) Can you clarify: Is your CoreDataManager file fulfilling pretty much the same role in your code as PersistenceController is fulfilling in the Xcode template? If I'm starting with the template, would you recommend editing the Persistence.swift file to be like your CoreDataManager, or is it a better idea to create a new file? I wonder because they both have the Singleton and that is what is confusing me some. These lines:
      static let shared = PersistenceController()
      let container: NSPersistentContainer

    • @azamsharp
      @azamsharp  3 года назад +1

      @@rillieux1792 yes it is the same role

  • @yuridavellodalmagro4960
    @yuridavellodalmagro4960 3 года назад

    Could you upload how to update a task?

    • @azamsharp
      @azamsharp  3 года назад

      Just change the values and perform save on the model object

  • @LukasLukas-kr7oy
    @LukasLukas-kr7oy 3 года назад

    👍

  • @UIRETU
    @UIRETU 3 года назад

    Hello dear author i have bought MVVM Design Pattern in iOS Using SwiftUI course but cant strart learn it because i have lattest version of xcode (and i havent files like AppDelegate and SceneDelegate) thaths why i am getiing a lot of errors in case, Can you rewrite lessons for lattest stable version of xcode. or say how can i get filw structure like your in my project thx

    • @azamsharp
      @azamsharp  3 года назад

      What errors are you facing?