Multiple API calls with Dispatch Group in Swift iOS Hindi tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024

ความคิดเห็น • 64

  • @MandeepSingh-ly3jj
    @MandeepSingh-ly3jj 3 ปีที่แล้ว +11

    Huge Respect for Ravi Sir, He is genius Guy, With the help of him videos related to an iOS , I was selected in reputed company , and now I have around 2year of experience and salary package is also great . all credit to Ravi sir. Salute to this man bcz I was selected in covid time and also I supported to my family with my earning. Again Really thanks from my heart. :)))

  • @anonymoussunny7127
    @anonymoussunny7127 2 หลายเดือนก่อน +1

    in this example, we are entering and leaving DG 2 times, so will notify called 2 times?

  • @rachitsharma8829
    @rachitsharma8829 ปีที่แล้ว +1

    Super cool .. 👌👌 ... As always you are ...
    I have question here, Instead of direct initialise DispatchGroup can we create wrappper for it with Lazy and as per our need we can call in our code ?
    other question is, How can i setup swagger part for testing my API ? If possible need your support
    Thanks

    • @CodeCat15
      @CodeCat15  ปีที่แล้ว

      You can create a wrapper for the DispatchGroup.
      Swagger Integration involves adding a package and configuring it. I am a dotnet developer to the core so integrating swagger is simple but if you're using a different stack, feel free to ask, and I can provide the specific steps. Additionally, you can refer to Swagger's official documentation for setup guidelines, as I'll also be using it as a reference.

  • @ParthPatel-ct2vz
    @ParthPatel-ct2vz 2 ปีที่แล้ว +1

    Dispatch Group is blocked thread is there any other way for async api call with same scenario
    Please make video for other ways to do api calls handling

    • @CodeCat15
      @CodeCat15  2 ปีที่แล้ว

      The dispatchGroup does not block your main thread and will perform the task concurrently, however using the wait( ) function of the DispatchGroup you may opt to wait synchronously else it won’t wait or block your threads
      If you don’t want to use DispatchGroup an alternative is operation queue

  • @MAbbas-ih7sz
    @MAbbas-ih7sz 3 ปีที่แล้ว +1

    Sir dispatch group main ma chahta hoon k meri pahi query ka response jab aye tu tab dosri query update ho wo kase karain ge

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      For serial api call I have a video do check it out and let me know if that answers your question
      Link: th-cam.com/video/II7bJmC64IY/w-d-xo.html

  • @shubhamdeshmukh9287
    @shubhamdeshmukh9287 2 ปีที่แล้ว

    closure Nightmare XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD XD

  • @nurlanakylbekov7266
    @nurlanakylbekov7266 3 ปีที่แล้ว +1

    I don't understand how we can notify if we got an error? I'm calling network API call with Result type closure. if the case .success I'm appending the user and leaving the group. if case .failure do I need to use DispatchQueue.main.async? Also, how can I call the second API after I got the result of the first API?

  • @ganeshwaghmode6692
    @ganeshwaghmode6692 หลายเดือนก่อน

    Very informative and explained in very simple way.

  • @princemehra6882
    @princemehra6882 2 ปีที่แล้ว +1

    Hi.. in my App i m hitting multiple Api's and saving there Json responce in Code Data but i m getting an error
    Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    so can you please tell how can i handle this error

    • @CodeCat15
      @CodeCat15  2 ปีที่แล้ว

      Push your code on GitHub so that I can check what’s going on and why are we getting this error, there can be multiple reasons for this which can be identified looking at the code
      My id: codecat15
      If you want to email then id is codecat15@gmail.com

  • @CaptainP777
    @CaptainP777 3 ปีที่แล้ว +1

    bhai aap itna sara knowledge late kaha se ho...yaar

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      haha majority from apple developer documentation :) aur kuch errors aur bugs bhi sikha dete hai, is topic pe kuch doubt hoga to puchna aur aapne iOS group k saath is video ko zaroor share karna

  • @polu9132
    @polu9132 3 ปีที่แล้ว +3

    never thought this scenario can be handled so easily with DG. Take a bow man. 👏

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      DG is pretty awesome in handling a group of task, do feel free to ask questions on this topic and do share the video with your iOS group and share the knowledge :)

  • @shubhambhadauria
    @shubhambhadauria 3 ปีที่แล้ว +2

    Hello Rahul,
    Nice to see your all hard work on explaining all things about Swift and SwiftUI and most of your explanation outside the code. For the last couple of months, I am following all the videos till up to date. Many things now I clearly understand. Thank you. Well, please explain on concept of semaphore in GCD and as well as with Dispatch Queue Label. If possible, I am looking for an explanation about these also. Thanks in advance.

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      I am working on the threading topics as of now to complete some of the concepts which were long pending, I hope to cover them all and you should also see some swiftui and combine videos in between. Do share the video with your iOS group and My name is Ravi and not Rahul :)

    • @NaviVlogs76
      @NaviVlogs76 2 ปีที่แล้ว

      @@CodeCat15 Dont worry about the name he is watching you...😀😅

  • @pramodkumargupta3063
    @pramodkumargupta3063 2 ปีที่แล้ว +1

    Thank you

    • @CodeCat15
      @CodeCat15  2 ปีที่แล้ว

      Glad it was helpful Pramod

  • @AnshikaPathak-mn3ej
    @AnshikaPathak-mn3ej ปีที่แล้ว +1

    This is really great Ravi since the day i started watching your videos , day to day im getting close to swift . please keep making videos more on regular basis . so that we can learn more n more from you .

    • @CodeCat15
      @CodeCat15  ปีที่แล้ว

      Thank you so much for your kind words and support! I'm thrilled to hear that my videos have been helping you with Swift. I'll definitely continue to create more content regularly. Stay tuned for more!

  • @darshantelang1535
    @darshantelang1535 3 ปีที่แล้ว +2

    Clean and neat way of handing multiple api calls on a screen. A thing to note here is when you have several different types of api calls, and assume if 1 of those calls don't return a response due to some issue ( say bug in server code), 1 dispatchQueue.leave() call will be missed out of n calls and even if remaining n-1 are executed, still there'll be no output on screen because dispatchGroup.notify() is not called unless the the number of enters match number of leave calls. This is the most important thing to be taken care of while using DispatchGroup.

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      There's one more way of handling that and I did that in the past for one of my friend, I am assuming it was using flatMap can't really remember need to revisit the code, you see the use case was even if one API fails you don't want to call the other APIs at all and I thought it was hard but then the solution turned out to be pretty short actually would create a video on that. You bring in a very interesting topic for conversation buddy and that indeed is a neat observation you got going there

  • @freekkarar204
    @freekkarar204 3 ปีที่แล้ว +1

    Dispatch Group Crash BUG IN CLIENT OF LIBDISPATCH: Too many nested calls to dispatch_group_enter().. Hi Ravi.. you know when this occurs

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      It's hard to tell without seeing the code but I will take a random guess here this may happen if you create more threads and there's an undocumented limit on the number of threads we can create which is 64. OR perhaps you missed to make call to leave function of the dispatch group

    • @freekkarar204
      @freekkarar204 3 ปีที่แล้ว

      @@CodeCat15 Thanks for replying. Dispatch Groups is unreliable and risky api to use. If any network calls doesn't give callback or if we have retries where callback called twice. App crashes. it relies on external factors. I would recommend devs to use Operations than DispatchGroups.

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      @@freekkarar204 It actually depends on how one implements it and a lot has to do with the tools that we are using like a hammer cannot be used where a needle is required. Dispatch group has a wait function and you can use that to wait till the time your operation returns you the response but make sure you are not waiting on the main thread. But then I always prefer using the highest level of abstraction if more control is required for my task which is the operation queue

  • @rj007love
    @rj007love 3 ปีที่แล้ว +1

    very informative video sir, I like the way you created array of requests. Previously I tried to add the dispatch group but didn't add due to miss information. Thanks for clarifying everything.

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      That’s awesome I am glad this was helpful Anil, plz do feel free to ask questions and do share this video with your iOS group on WhatsApp or Facebook

  • @iamwaseem99
    @iamwaseem99 3 ปีที่แล้ว +1

    Thanks for this video bro. I guess next topic will be on operation queues to handle dependencies. Also make a video on DispatchSemaphore and compare it with DispatchGroups. ✌🏻

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      You indeed are a mind reader Waseem, yes the next session is on operation queues they handle dependencies more elegantly as compared to DG. As of now am trying to cover most of the threading concepts which were not present in the channel by showing how they can solve common uses cases of our iOS project. Do share the video with your iOS group 😊 and feel free to ask questions on this topic

  • @U-and-Mee
    @U-and-Mee 2 หลายเดือนก่อน

    great

  • @shashankmishra5329
    @shashankmishra5329 3 ปีที่แล้ว +1

    Great video for multiple api call with clean code... Great work.

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      I am glad this was helpful, do ask questions on this topic and do share the channel with your iOS group.

  • @rj007love
    @rj007love 3 ปีที่แล้ว +1

    can you put some light on Static Dispatch and Dynamic dispatch in any of your video?

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      Sure I am going topic by topic next video will be on operation queues solving the second part of the problem which is dependency based requests and there’s also one more short video i plan to make using protocol oriented programming which is for multiple data sources for a single screen.

  • @mazedar_tv
    @mazedar_tv 3 ปีที่แล้ว +1

    Its similar like OperationQueue adddependency. But via using dispatchgroup.leave() e can controll, at which point the task will be ended. Here Ravi has used api example which is best demonstration for the task

  • @shubhamdeshmukh9287
    @shubhamdeshmukh9287 2 ปีที่แล้ว

    love you bro

  • @shahriarmahmud7850
    @shahriarmahmud7850 3 ปีที่แล้ว +1

    @codeCat what is the purpose of code sanitiser ?

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      Thread sanitizer are used to detect any issues with the code that you write, mostly used in debugging memory related issues which you can fix, the only issue with enabling them is that they kind of make your build process a little slow coz they are analyzing your code but hey a slow build is better than a runtime crash

  • @pushpabisht4850
    @pushpabisht4850 2 ปีที่แล้ว

    Useful video

  • @ramanihitesh601
    @ramanihitesh601 3 ปีที่แล้ว +1

    thanks sir really good video i am learn more ..

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      Hey Ramani, am glad this video was helpful 😊

  • @deepakkumar-qz1ud
    @deepakkumar-qz1ud 2 ปีที่แล้ว +1

    Brother you are Amazing✌✌✌

    • @CodeCat15
      @CodeCat15  2 ปีที่แล้ว

      Thank you so much bro 😀

  • @JunaidKhan-ny8tu
    @JunaidKhan-ny8tu 3 ปีที่แล้ว +1

    My favourite TH-camr 👍👍👍👍 I have so much these scenarios in our app

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      Am glad now you will be able to resolve them more elegantly using dispatch group. Do share the video with your iOS group and feel free to ask questions on this topic

    • @JunaidKhan-ny8tu
      @JunaidKhan-ny8tu 3 ปีที่แล้ว

      @@CodeCat15 yeah sure sure 👍

  • @nagarajvrao7249
    @nagarajvrao7249 3 ปีที่แล้ว +1

    Performs better than nested closure?

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      Hey Nagaraj, dispatch group indeeds performs better than nested closure and I have made a quick video for this and released it just now so do check and let me know if you have any questions regarding the same
      Link: th-cam.com/video/HucU2jBQffc/w-d-xo.html

  • @NishantNarola
    @NishantNarola 3 ปีที่แล้ว

    Nice tutorial. Can you make video on multiple images upload along with other parameters using alamofire

  • @rakeshraushan8217
    @rakeshraushan8217 3 ปีที่แล้ว +1

    This is what I was looking for. Thanks 😎

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      Glad you found it Rakesh, and I hope this video was helpful

  • @ajeetsharma7271
    @ajeetsharma7271 3 ปีที่แล้ว

    Superb. Thanks Ravi

  • @Abdulmoiz-ww3dj
    @Abdulmoiz-ww3dj 3 ปีที่แล้ว +1

    Great work sir 👍

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      Thank you Abdul

  • @himanshusaini1404
    @himanshusaini1404 3 ปีที่แล้ว +1

    Niceeee

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว +1

      I am glad this video was helpful, do check out the second part of the video where we compare the performance of nested closure and dispatch group
      Link: th-cam.com/video/HucU2jBQffc/w-d-xo.html

  • @himanshukumar_26
    @himanshukumar_26 3 ปีที่แล้ว

    What about thread safety here. Assuming we have 100 department for which we need to fetch data. The response of those data need to add into an array from different threads. Arrays are not thread safe will it not crash or create issue on data show.

    • @CodeCat15
      @CodeCat15  3 ปีที่แล้ว

      Given that requirement fetching 100 records of department is just too much, data should always be fetched on-demand.
      If you fetch everything at once even the unwanted records you are just consuming space in the users phone that’s a bad system design.
      Having said that, the assumption you made on the approach is not foolproof and will fail if you just keep on storing everything in one giant array doesn’t matter what approach you go with it.
      Array gets big and soon the app runs out of memory or worse, who knows threading bugs are unpredictable man. 🤷‍♂️
      Anyways, If you want to walk that path then maybe first try with groups see if it really fails, have a test case as a proof that it fails or not and then maybe you can use semaphores or barriers.
      I don’t usually recommend locks I always try to avoid them coz of their unpredictability.
      Dispatch group is not a silver bullet for every use case that we face but yes it surely will give you a good starting point.
      There are many classes in the dispatch framework and every class handles a different use case so choose your tools wisely.

  • @sanjaymorya6029
    @sanjaymorya6029 2 ปีที่แล้ว

    Awesome Bro 👍🏻