async await with API example | Swift Hindi tutorial

Поділитися
Вставка
  • Опубліковано 2 сер 2024
  • Async await is a new feature in Swift 5.5 and it helps in performing async operations, previously we were using classes such as dispatch queue, operation queue, and dispatch group but with async-await asynchronous calls are easier.
    Async await not only helps us to perform a complex async task but also help us in writing clean readable and managed code, in this video, we will explore async await example in swift for complex API calls like serial API calls and serial API dependency
    Given are the chapters covered in this video
    0:00 introduction
    0:50 existing approach for async operations
    1:53 issues with existing approaches
    5:35 syntax of async await
    7:46 async await demo
    8:31 serial API flow with swagger
    9:35 existing approach code flow
    10:46 creating async function in HTTP utility
    14:22 comparing the existing approach of API calling with the new approach
    15:16 replacing escaping closure with async
    20:46 summary of the code
    21:41 subscribe like and share
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ✅ 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/1eTZp...
    -----------------------------------------------------------------------------------------------------------------------
    Link mentioned during the videos
    API series playlist: • URLSession: Get and po...
    Async await bug I logged: bugs.swift.org/browse/SR-14468
    Async await stack corruption bug: forums.swift.org/t/swift-5-5-...
    ############################################
    Connect with me on social media
    📧: codecat15@gmail.com
    🐦: / codecat15
    Facebook: / code.cat.792
    Github: github.com/codecat15
    ###########################################
    #asyncAwaitSwift #asyncSwift #swiftHindiTutorial

КОМЕНТАРІ • 90

  • @afzalansari-jq4qd
    @afzalansari-jq4qd 2 роки тому +18

    i can guarantee that even paid course anywhere dont teach you like how you explain each and every thing keep up the good work its really helpfull for developers like me to find content like yours

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

    Learning a lot from you. Would you kindly include subtitles to your videos? They would be really beneficial.

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

    This is my go-to channel for iOS stuff. Learned alot in past from you and still learning. What sets you apart from other is you tell us not only how to do things but also how not to do things also.
    Ravi bhai mast kam karata hai tum, mereko tumako ♥️ se thank you bolane ka hai.

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

      Thank you for your kind words bhai, I am glad the video was helpful

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

    Love to see you back with fire 🔥! Awesome video!

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

    I really like all your videos... you explain every topic in a very simple and interesting way.

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

      Thank you for your kind words Ajay 😊 plz feel free to ask questions and do share the video with your iOS group

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

    amazing series Ravi. thanks a lot. binge watched the whole playlist. 👌

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

      Glad it was helpful Siddharth

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

    Good explaination video found gold in heap :)

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

    why your content so good :) ...You are really saviour...you just explain each and every bit in a such a way that where anyone can understand. kudos to you.. sharing your videos to my fellow mates. Thank you once again.

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

      Thank you for the kind words, I am glad the content is helping you, feel free to ask questions on this topic and do share the channel with your iOS group

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

    This was much awaited video. !!❤️

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

      Indeed, I have mentioned the reason why the video was delayed but I am glad now it’s out 😊 plz feel free to ask questions and do share the video with your iOS group

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

    Hi Ravi , I really like all your videos... You explain every topic in a very simple and interesting way.

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

      Thank you Garima, am glad these videos are helpful. Please feel free to ask questions and do share the channel with your iOS group 😊

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

    Awesome learning with simplest manner... thanks a lot.. keep doing great work :)

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

      I am glad this video was helpful, please feel free to ask questions on the topic or share the video with your iOS group

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

    Great Sir !! Excellent Work

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

      Glad this was helpful 🙏

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

    Helpful video, as always 👍👍

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

      Glad this was helpful 😊

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

    Great Sir G !! Excellent Work.

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

      Thank you 🙏 I am glad this was helpful, please feel free to ask questions and do share the video with your iOS group

  • @JunaidKhan-ny8tu
    @JunaidKhan-ny8tu 2 роки тому +1

    itni mehant(hard-work) Ravi Bhai

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

      Thank you Junaid 🙏

    • @JunaidKhan-ny8tu
      @JunaidKhan-ny8tu 2 роки тому +1

      @@CodeCat15 typo mistake . Too much hard work you do for your followers. Keep it up

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

    Superb! Ravi, Thank you so much.

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

      I am glad this was helpful 😊

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

    Thanks for another informative video.

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

    Excellent 👏👏👏👏👏👏👏👏

  • @kalpeshjethva598
    @kalpeshjethva598 4 місяці тому

    Thank you Ravi for this wonderful series.

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

      Glad it was helpful Kalpesh, please feel free to ask questions and do share the video with your iOS group.

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

    Thank you Sir for these informative videos. Very helpful & we always learn new things in each video.

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

      Am glad this was helpful 🙏 hopefully the content will be helpful even while you are preparing for interviews

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

      @@CodeCat15
      Thank You for your kind words

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

    Thank you very much for this video. I love your videos I got lot of confidence after subscribing your channel.

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

      Glad that the channel has helped you this much, thank you for your kind words and feedback means a lot to me

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

    I was thinking how will we break the await call sequence from the first function call which is not async in nature i.e here from view controller.. now got to know that "Task" helps here to break that await call chain. Thanks again for sharing another great content.

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

      I am yet to try async await with SwiftUI and am assuming there it would be even more helpful as compared to UIKit thanks to the pub-sub approach, I don’t really like the Task approach but it is what it is I guess.
      Glad the video the was helpful 🙏 feel free to ask questions and do share the video with your iOS group

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

    Thank you so much bro

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

      No problem, I am glad this was helpful

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

    @codecat create one video for UITableviewDiffableDatasource and UICollcetionDiffable

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

    Hi Ravi, Thanks a lot for sharing this video. It's so fruit full. But I Have doubts for same: we are creating same nested cycles after one API to another API. It's like same dependency one API to another, so how we fixed this? Apart from that everything is awesome.

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

    Thank you 😊

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

      Glad it was helpful, do share the video with your iOS group and feel free to ask questions 👍

  • @Rahul-jf5kf
    @Rahul-jf5kf 2 роки тому +1

    Thank you so much Ravi, this is the most readable, understandable and easy to maintain code for webservice call I have seen, One doubt I have, in case of error(error in http response or error in error variable) we want to display error Message in alert, Where should I place it, 1) In HttpUtility then i need to pass reference of controller thorough all functions or 2) in ViewContoller itself in this case code gets repeated for all viewcontrollers

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

      the error can be returned in the delegate function and can be displayed on the main thread on the view controller

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

    Thank u

  • @user-jb4cz2ee2d
    @user-jb4cz2ee2d Рік тому

    I like and want to use the Async await in one of the application but there are some rest APIs that are getting failed to respond, how can I manage a retry call with Async await. If I want to retry more then 3 times and still fail then I need to continue with the next api...How can I manage the retry flow can you pls explain?

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

    Video is awsm as usual. Very helpful to implement to own project .
    Means this is working for any asynchronous call.can we avoid dispatch group uses?

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

      Dispatch group solves a different problem as compared to async await and hence it’s too early to say let’s dump the dispatch framework and use async await permanent.
      If I want to call 5 APIs all at once and I don’t care about the sequence then in that case DG is more useful as compared to async await

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

    Thank you Sir, for this amazing video with such a nice explanations. Can you do time test for different approaches?

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

      That’s a wonderful suggestion I would love doing that in the future videos, I have made a note of it and to test this I have some complex use cases in mind as well.
      Thank you for suggesting this

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

      @@CodeCat15 Welcome Sir

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

    Thank you Ravi for sharing latest important information and I really like it 👍Can we achieve multiple calls at a time by this async / await?

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

      Glad it was helpful Priyanka, as the this SO post it seems it can be done, I have not tried doing that yet but surely will release an IG video on it if needed
      stackoverflow.com/questions/70172361/how-to-run-multiple-api-call-simultaneously-using-async-await-in-swift

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

    the great explanation. Loved it..! I would like to know how we can unit test the HttpUtility class as this has the generic function.

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

      The HttpUtility class has URLSession calls which is an apple class and has no business logic or any special cases, so writing test cases for this library would be futile because you would write test cases for your service layers which will use this utility so in a way you would end up indirectly testing the utility.

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

    can you please tell how to write unit test as well for async await function. you can drive from TDD

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

      One of the highly recommended resources for understanding Clean Architecture be it iOS or any other technology that you learn in the future is the book "Clean Architecture: A Craftsman's Guide to Software Structure and Design" by Robert C. Martin (Uncle Bob). This book provides in-depth insights into Clean Architecture principles and how to apply them to iOS development.

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

    Hello Ravi,
    I hope you doing very well.
    If we have to show any alert when error comes from server or request time out then how can we do it?
    Some time we have to create one error screen for reload data so how can we manage?

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

      In this case you may display the error in the Task struct, although I am not a big fan of how its done, since this feature is new I too am playing around with it and will be showing more of it in the coming videos as the swift community will be adapting async await heavily in their code.

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

    Thanks Ravi. This is really nice..
    Just one query. Async/await runs on which thread main thread or global thread?

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

      When you use async/await in Swift, the code runs on a separate concurrent thread managed by the system, rather than the main thread.

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

    Before I watched hecking with swift video all most two months ago related of async wait
    But not show bug
    Thanks you for providing latest method with own language (Hindi)

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

      When I found one bug in the toolchain I was a little hesitant to show this feature, coz I knew this was a complex integration and bugs are bound to come and hence I delayed this.
      Every second channel was showing async await and I was like damn everyone on UA-cam is in a race to show this feature first 😅 for views maybe but I am tortoise in that case

  • @PankajKumar-vf5xm
    @PankajKumar-vf5xm 2 роки тому

    Hello Sir,
    Thanks to you for another nice tutorial.
    I am stuck in my project for making a walkie talkie app. I am unable to awake my application using notifications when app in background or closeed state. Can you please help me. I tried everywhere but no help. Can i contact you by any medium.

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

    Hi Ravi, what if getToken() method takes much time (1 min), will getPayroll gives error?
    If yes, how to dependency for those 2 async methods (without operationqueues)?

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

      You can use async await now to handle such use cases and that way when the first operation fails you can send the appropriate message from your service layer to the viewModel.
      If an api is taking more than a minute then that’s a performance bottleneck of that api and the api developers must fix that on priority

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

      @@CodeCat15
      let resultFirst = await testAsyncWaitFirstAPICall() //takes 10 sec
      let resultSecond = await testAsyncWaitTwoAPICall(input: resultFirst) // takes 5 sec
      print("hello test") // some code after async-await
      Que: Will print executed immediately OR after await completion? What I understand is, await will block the current execution flow, correct?

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

    I like async await but don’t like the do catch block everywhere

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

      same here but I think it's a necessary evil to make sure to capture unexpected behavior of the application a tradeoff to live with I guess

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

    Hello
    In second view controller i click on button and call this code which dismiss the controller
    Self.dismiss(animation: true, completion: nil)
    What i want is after press the button it took 5 seconds of time to dismissed the controller screen

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

      Task awaits the async operations to complete, a little detail is provided in the actor video as to how Task works and maybe the delay is because Task is trying to finish the async task first and then dismiss the controller.

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

    Bro Push notification pe video banao na

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

    Nice Tutorial !
    one question do u know how to check Crashlytics Crash

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

      This link will guide you out for the crashlytics logs
      firebase.google.com/docs/crashlytics/test-implementation?platform=ios

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

      @@CodeCat15 thanks ravi

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

    Please tell me in English

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

      What's your question? I will be happy to explain it for you.

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