Core data CRUD using repository pattern in swift Hindi tutorial Part 1

Поділитися
Вставка
  • Опубліковано 20 чер 2020
  • Core data crud using repository pattern in swift Hindi tutorial covers how to use a repository design pattern with core data along with few clean code tips. Core data for beginners can be challenging but with this ios core data tutorial, we shall try to simplify learning core data and make it a much simple and easy process.
    This core data tutorial talks about some of the topics which are helpful for beginners in swift about some good coding habits they can choose while ios application or just from a learning perspective.
    -------------------------------------------------------------------------------------------------------------------
    Code like a pro playlist: • Code like a pro swift ...
    -------------------------------------------------------------------------------------------------------------------
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ✅ Subscribe to the channel and stay ahead of everyone by following the right way for writing clean code in swift. 🔥🔥🔥🔥🔥
    🔗Click on the link to subscribe: ua-cam.com/users/codecat?sub...
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    -----------------------------------------------------------------------------------------------------------------------
    📥 Download the source code from
    Github: github.com/codecat15/UA-cam-...
    Google Drive: drive.google.com/file/d/1zGlZ...
    -----------------------------------------------------------------------------------------------------------------------
    🎶 Royalty-free Music: www.bensound.com
    ############################################
    Connect with me on social media
    📧: codecat15@gmail.com
    🐦: / codecat15
    Facebook: / code.cat.792
    Github: github.com/codecat15
    ###########################################
    #repositoryPatternInSwift #CoreData #CRUDInCoreData

КОМЕНТАРІ • 94

  • @CodeCat15
    @CodeCat15  4 роки тому +6

    Working with the local storage can be a little overwhelming if you are not following the right design pattern be it core data or any third party tool, in this tutorial I explain the following topics
    1. Why singleton approach is not good for local storage along with technical reasons
    2. Introduction to repository pattern
    3. How to avoid breaking abstraction
    4. Some fun with Generics in the persistent Storage class
    And some of my examples as usual
    This is the first part and the second part will be out this week, am not going to keep you waiting for an entire week for this. Please do like this video and do subscribe to the channel and share it with your iOS group

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

      Great video
      Just one suggestion
      Instead of using forEach loop to convert cdEmployee to employee, you can use map function

  • @user-go3dt2in3m
    @user-go3dt2in3m 7 місяців тому +2

    your channel is getting addictive to me

    • @CodeCat15
      @CodeCat15  7 місяців тому

      Glad it’s helpful

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

    Generally, I don't comment on videos, but today taking time to comment. because it is worth watching and thumbs up. No words to say. Actually, I am an iOS Trainer but I learned something new from you.
    Thanks

  • @madmaxcoder6209
    @madmaxcoder6209 4 роки тому +1

    This is premium quality content for which people pay and watch and you are just giving it for free and explaining in very simple term. Thank you for sharing this Ravi.

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

    very helpful!

  • @imhrithik1713
    @imhrithik1713 Рік тому

    Good

  • @techi-vintechnologies7573
    @techi-vintechnologies7573 4 роки тому +1

    Hi Ravi Sir, This is Vinod Mahale. (iPhone batch no 17, Quagnatia..) Glad to see you here. Got your channel link from Arjun...

    • @CodeCat15
      @CodeCat15  4 роки тому

      Hey Vinod long time no see, yes i did share my channel yesterday with Arjun, hope it helps you in understanding the core concepts of swift and thank you for your kind words. Do share it with other members as well and do ask them to subscribe

    • @techi-vintechnologies7573
      @techi-vintechnologies7573 4 роки тому +1

      @@CodeCat15 Sure sir

  • @vimobee
    @vimobee 4 роки тому +2

    Thanx Ravi, I wish I could give you more likes for the video 😊. Loved the way you organised the code. The channel deserves more subscribers for the quality of contents you are providing. Looking forward for next video of the series. 👍

    • @CodeCat15
      @CodeCat15  4 роки тому

      Thanks Vikas that’s really nice of you to say such kind words. Please feel free to ask questions on this topic and share this channel with your iOS group.

    • @vimobee
      @vimobee 4 роки тому +1

      ​@@CodeCat15 Could you please explain id as CVarArg part of the predicate. When should we caste any property as CVarArg ?

    • @CodeCat15
      @CodeCat15  4 роки тому

      Sorry @Vikas I could not get back to you, I am not getting notifications for the comments so i manually check. So coming to your question if the parameter was a string or int then the conversion was not required but in the case of UUID since UUID does not conform the protocol CVarArg the manual conversion was needed. so when I did "Id as CVarArg" I am converting the UUID to a va_list which is variable argument list in C programming. Let me know if that answers your question and once again apologies for not getting back in time.

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

    good one brother

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

      Welcome to the channel Vashu, am glad this video was helpful. Please feel free to ask questions on this topic and so share it with your iOS group 😊

  • @shahbaze63
    @shahbaze63 4 роки тому +1

    Thank you so much for this..

    • @CodeCat15
      @CodeCat15  4 роки тому

      Am glad this was helpful @Shahbaz. Please feel free to ask questions on this topic will be happy to answer them

  • @AhsanZahidDevb
    @AhsanZahidDevb 4 роки тому +1

    BEST ONE 👍🏻

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      Hey Ahsan, welcome to the channel thanks a lot for your comment, please feel free to ask questions on this topic will be happy to answer them and do share this with your iOS group on WhatsApp or Facebook

    • @AhsanZahidDevb
      @AhsanZahidDevb 4 роки тому +1

      Sure

  • @AnuragKashyap17
    @AnuragKashyap17 4 роки тому +2

    Bro, I am really thankful that you are here to help developers like me , whenever you say “Creative Developer” I tend to creat a creative image of mine in my mind 😅 where I see myself doing creative things 😐

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      You see today your code may not be that good and don’t feel bad about it, practice it, always think before you code, read more on solid principles. Am sure you will write code 100 times better than me.
      It took me time to practice, implement, think like this and it was a bumpy ride of trial and errors.
      There’s a story behind how i started to code like this or whats my journey in programming i will share it someday on my channel

    • @AnuragKashyap17
      @AnuragKashyap17 4 роки тому +1

      Code Cat I will be waiting for that , I am sure it will definitely help me , you lectures are so amazing that when the tutorial completes I actually say to myself arey khatam why it’s not more 😅 I literally get so engaged with the content ❤️❤️❤️

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      @@AnuragKashyap17 Second part iska mai Wednesday tak release karne ka try karta hu and those are kind words thanks man it means a lot to me. I think ye 1000 subscriber special video banata hu mai.

    • @AnuragKashyap17
      @AnuragKashyap17 4 роки тому +1

      Code Cat Arey wahhh!!!! Congratulations in advance ❤️❤️❤️ You deserve a ton of subscribers bro 🤘🏽

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      Thanks yaar, socha nahi tha aisa kabhi hoga coz maine assume kiya tha ki 200 ya 150 hoga but I will surely share a thank you video and my journey in programming.

  • @rahulkatore5563
    @rahulkatore5563 Рік тому

    Thank you!, why you have not added this operations in earlier CoreDataDemo Project??, that will be very helpful to understand.

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

    Sir, ye core data ke Operations kis thread pr hote hain (main or background) if we do not specify any explicitly ?

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

    Hi Ravi. Can you make a video on how to make a boilerplate for core data such that I can directly download the files and include them in my code? More like a boilerplate instead of "Employee", or "CDEmployee" entity, we can take any entity that our project contains. (Using Generics)

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

    hiii ravi .... i am became ur fan..... u r too too gud.... u r talking both in hindi and english inbetween thats y I understand Language is the problem for me . I dont know hindi. Its my kind request for you to do explain in English.. It will be very helpful for many...

    • @CodeCat15
      @CodeCat15  3 роки тому +2

      Hey Sharmi, I would like to apologize if language has caused you issues in understanding the topic, I will be very much happy to answer your queries on this topic so please do feel free to ask questions.
      I think it's almost time to have a poll on this, you see I would be happy to make a video in English but mostly the viewers prefer hindi, but from time to time I keep on doing a temperature check to ask my viewers what they want and soon I will add a poll for this on my instagram handle :)

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

      @@CodeCat15 k bro ...

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

    Hi, In EmployeeDataRepository swift file in protocol Employee comes from where??

  • @MandeepSingh-ly3jj
    @MandeepSingh-ly3jj 4 роки тому +1

    I really like background music and motivation thought on wallpaper . I learn so many thing from this video. very simple and easy to understand . I think you are big fan of Einstein.

    • @CodeCat15
      @CodeCat15  4 роки тому +2

      Thanks a lot for the comment, I am just a curious person who wants to explore and have fun with technology so I keep on moving from one technology do couple of projects in that and then move to the next one.
      My Dad, Einstein, Nikola Tesla, Bruce Lee and Steve Jobs are my greatest inspirations of all time. Writing clean code is very easy and that's all I want to show from this channel.

    • @MandeepSingh-ly3jj
      @MandeepSingh-ly3jj 4 роки тому +1

      @@CodeCat15 Sir you follow these genius and programming and I follow your your UA-cam it will clear my all concept surely due to explanation in simple and clear with real life example . In IT world specially in India Nobody guide to junior developer properly they think if they guide to junior and if junior achieve excellence and then their job or position will be in bad situation , means they used politics agenda in company

    • @MandeepSingh-ly3jj
      @MandeepSingh-ly3jj 4 роки тому

      @@CodeCat15 With the help of your channel lots of junior or mid level developer will be understand what the things is going on in iOS and difference between quality code and unwanted and hard to manage code.

    • @CodeCat15
      @CodeCat15  4 роки тому +2

      Nobody guided me too so I know the pain and I know what you might be going through, I am not saying its an easy path but all we should focus on is improving our self as a programmer.
      Not all seniors are like that some are very kind and try to help the junior devs as much as they can but its very unfortunate that you have to come across such creative seniors. I think if we just do our job and make sure we cover all the use cases then people no matter how bad they play politics won't be successful as our work speaks for itself.
      This is my advice to you, just focus on your work, make sure all the use cases are covered, my channel is very new so i may take time to cover some topics but ultimately I will cover them with easy examples.

    • @MandeepSingh-ly3jj
      @MandeepSingh-ly3jj 4 роки тому +1

      @@CodeCat15 Sir, Thanks for your advice

  • @AnuragKashyap17
    @AnuragKashyap17 4 роки тому +1

    Bro, Please do try to explain dependence inversion in this topic as well. I know you have already explained and there is video out there for this but please do explain the same here as well, like fetching the data from the api and then storing it to the database for which we will be having different class for Core data handling and API handling so I guess in that case Dependency Inversion can be demonstrated again, please correct me if I am wrong. That will actually be a real life scenario when coding. And will actually give a more clearer vision on both these topics.

    • @CodeCat15
      @CodeCat15  4 роки тому +2

      the dependency inversion principles states that the high level modules do not depend on low level modules, so in this example, if you observe I have a protocol in the repository so all I am saying is yes it is one of my topics for the core data playlist I already thought about this because this scenario has its own complexity which we need to dealth with because you will have two repositories here APIRepository to fetch data from the server for employee and a database repository for local storage and fun fact APIRepository cannot and should not call DatabaseRepository because then you introduce coupling between them, will I use DI or something better let's find out when I release that topic.

    • @AnuragKashyap17
      @AnuragKashyap17 4 роки тому +1

      Code Cat cool enough 🤘🏽🤘🏽🤘🏽

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

    from where did u get this persistantstorage object can we handle persistant storage object in base data repository globally ?

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

      In the first part of core data I am explaining why I created this singleton class and what was the though process behind it. Do check the introduction to core data video given below is the link for the same
      Link: ua-cam.com/video/wAy3S1MnKYY/v-deo.html

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

    Sir. I'm facing a problem on 18:40
    let predicate = NSPredicate(format: "id==%@", id as CVarArg)
    the like show me this error "Cannot convert value of type '(any AnyObject).Type' (aka '(any AnyObject).Type') to type 'any CVarArg' in coercion | Insert ' as! any CVarArg'

    • @CodeCat15
      @CodeCat15  Рік тому

      if you do the force unwrapping then does it work?

  • @HirenMistry0125
    @HirenMistry0125 4 роки тому +1

    Hello,
    i have save four textfiled data, but when i fetch and show on tableview it shows only one entry (last textfield data), any suggetion?

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      Seems like a data binding issues, make sure all those values are set to the attribute of the entity.

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

    We really have a similar mind Code Cat.

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

      Are you my twin brother Nitesh hahaha cheers 🍻

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

    Hi, Can you make one video for which store data from API response with the relationship if possible?

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

      I am going to, actually there are 2 maybe 3 videos which I want to explore with core data and the topic you requested Dipak is one of them.

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

    Can we use higher order function for filter ?

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

      Yes you can at it works well too :)

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

    Thank you. At time 15:11 what shortcut you used at line 41?

    • @CodeCat15
      @CodeCat15  Рік тому

      its not a short cut but default suggestion from xcode itself I just pressed enter that's all

    • @goutamdas641
      @goutamdas641 Рік тому

      @@CodeCat15 Okay 👍

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

    ye CVArg kya hia ? Please explain these things while creating the videos thansk

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

    Why do we declare singjeton class as final??

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

      We don’t want that class to be inherited by other class and hence to make sure that does not happen we mark it as final
      If not then someone will get an idea of subclassing it and now you have two classes with same behavior manipulating the core data store that’s violation of single responsibility principle

  • @saqibrehman8692
    @saqibrehman8692 4 роки тому +1

    sir image ki primitve type kkyya h to .. image variable kaise bnne ga

    • @CodeCat15
      @CodeCat15  4 роки тому

      Hello Saqib, welcome to the channel image ko aap as data store kar sakte ho, so you do have data as a type in core data, to using that you can store binary, there are other ways too of doing that maine part 2 mai usse explain kiya hai. Is video mai agar aapko koi doubt ho to please puchna zaroor aur ye channel aapne iOS group mai bhi share karna

  • @Cricketingshorts786
    @Cricketingshorts786 4 роки тому +1

    can u please tell me when u will upload next part of the video

    • @CodeCat15
      @CodeCat15  4 роки тому +1

      Will be done in this week mostly by Wednesday, let me know if you have any questions on this and please do share this with your iOS group

    • @Cricketingshorts786
      @Cricketingshorts786 4 роки тому

      @@CodeCat15 hey waiting for video

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

    Can you show us how to create that Models also? coordination is missing when trying the trial of this tutorial in Xcode .

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

      I am assuming you mean the core data models? Steps to create them are shown at 10:04 let me know it that’s what you are looking for

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

      @@CodeCat15 not there. It’s here 15:21. I’ve looked into your GitHub files for that. No problem. 🙂

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

      Oh okay cool 👍 feel free to ask questions on this and do share with your iOS group if this video was helpful

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

      @@CodeCat15 sure👍

  • @paonej4033
    @paonej4033 10 місяців тому +1

    Without going for repository pattern why can't we use generic singleton class for CRUD operations

    • @CodeCat15
      @CodeCat15  10 місяців тому

      Here are the drawbacks of using a generic singleton class for CRUD operations
      1. Lack of separation of concern: Generic singletons mix data access logic with application logic, violating the principle of separation of concerns and making code harder to maintain.
      2. Testing Challenges: Tight coupling to data sources in a singleton makes unit testing difficult, as you can't easily substitute mock data for testing purposes.
      3. Limited Adaptability: Generic singletons lack the flexibility needed to adapt to changing data access requirements, potentially causing difficulties when switching data sources or optimizing data access.
      4. Scalability Challenges: As your codebase becomes more complex and your data access needs become more specialized, maintaining a single monolithic class for all CRUD operations can become unwieldy. The repository pattern allows you to create specialized repositories for different entities or data types, promoting a more scalable and maintainable architecture.
      while using a generic singleton class for CRUD operations may seem like a straightforward solution initially, it can lead to several drawbacks, including poor separation of concerns, reduced testability, limited flexibility, and scalability challenges.

    • @paonej4033
      @paonej4033 10 місяців тому +1

      @@CodeCat15 Thanks ravi for the sharing disadvantages of using generic singleton pattern

    • @CodeCat15
      @CodeCat15  10 місяців тому

      Glad it was helpful, please feel free to ask more questions

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

    Sir how to add multiple entities??

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

      Multiple entities as in from an API?

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

      @@CodeCat15 no no sir, you know we can create multiple entities and can make relationship between these entities

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

      You need to have the entities defined in the xcdata model with their relationships and then you can just inject data as shown in the demo. Whatever the case you need to have all your entities with their relationships defined in the model before you write the code, if you try to do things dynamically then it may cause issues or worst versioning can be a pain to deal with. Let me know if that answers your question and if not send me an email with a sample codebase of what you are trying to accomplish with what have you tried so far

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

      @@CodeCat15 ok sir..sure

  • @hareeshgangadhara415
    @hareeshgangadhara415 4 роки тому +1

    Employee comes from where

    • @CodeCat15
      @CodeCat15  4 роки тому

      The employee record will be coming from the UI. User will enter the record and it will be saved using core data, did I answer your question? If not then please feel free to ask I will be happy to answer them.
      Also there's a part 2 of this video I recommend seeing that as well

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

      @@CodeCat15 Have you made any struct named Employee cause the NSManagedObject is CDEmployee right and in the protocol you are declaring Employee. Thats what he is asking. Whether we have to make a struct which has same as CDEmployee

  • @itscrypto-techtime89
    @itscrypto-techtime89 Рік тому +1

    It's incomplete video.

    • @CodeCat15
      @CodeCat15  Рік тому

      Checkout the core data playlist you’ll find the second part there.

  • @iSubhoo
    @iSubhoo 2 місяці тому +1

    Too much Complicated Video, also at 18:30 why using NSPredicate, what is it? why using format: "id==%@" nothing emplained. Just coding is going on.

    • @CodeCat15
      @CodeCat15  Місяць тому

      Sorry if you feel that way, NSPredicate is a class that works like a filter in core data it's similar to a WHERE clause in SQL, hope that helps.

  • @gowthamravi7353
    @gowthamravi7353 4 місяці тому +1

    Hi Sir. Why do we need convertToEmployee method when the data we are getting from fetchManagedObjects method is already an array of the type we declared?
    func getAll() -> [Employee] {
    guard let employees = PersistentStorage.shared.fetchManagedObject(managedObject: Employee.self) else { return [] }
    return employees
    }
    Is this code not enough on getAll method?

    • @CodeCat15
      @CodeCat15  Місяць тому

      You could do that but then it will expose the domain model to the client layer which is not advisable because the client might not need all of those OR before passing to the client there could be certain data-formatting that you may need to do like formatting the date based on the user's locale OR formatting a string to remove special character and hence you should always maintain a separation between domain and the client data model