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
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
Thank you Afzal for your kind words means a lot to me 👍
true
💯 true🔥
Learning a lot from you. Would you kindly include subtitles to your videos? They would be really beneficial.
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.
Thank you for your kind words bhai, I am glad the video was helpful
Love to see you back with fire 🔥! Awesome video!
More to come!
I really like all your videos... you explain every topic in a very simple and interesting way.
Thank you for your kind words Ajay 😊 plz feel free to ask questions and do share the video with your iOS group
amazing series Ravi. thanks a lot. binge watched the whole playlist. 👌
Glad it was helpful Siddharth
Good explaination video found gold in heap :)
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.
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
This was much awaited video. !!❤️
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
Hi Ravi , I really like all your videos... You explain every topic in a very simple and interesting way.
Thank you Garima, am glad these videos are helpful. Please feel free to ask questions and do share the channel with your iOS group 😊
Awesome learning with simplest manner... thanks a lot.. keep doing great work :)
I am glad this video was helpful, please feel free to ask questions on the topic or share the video with your iOS group
Great Sir !! Excellent Work
Glad this was helpful 🙏
Helpful video, as always 👍👍
Glad this was helpful 😊
Great Sir G !! Excellent Work.
Thank you 🙏 I am glad this was helpful, please feel free to ask questions and do share the video with your iOS group
itni mehant(hard-work) Ravi Bhai
Thank you Junaid 🙏
@@CodeCat15 typo mistake . Too much hard work you do for your followers. Keep it up
Superb! Ravi, Thank you so much.
I am glad this was helpful 😊
Thanks for another informative video.
You bet!
Excellent 👏👏👏👏👏👏👏👏
Thank you Sai
Thank you Ravi for this wonderful series.
Glad it was helpful Kalpesh, please feel free to ask questions and do share the video with your iOS group.
Thank you Sir for these informative videos. Very helpful & we always learn new things in each video.
Am glad this was helpful 🙏 hopefully the content will be helpful even while you are preparing for interviews
@@CodeCat15
Thank You for your kind words
Thank you very much for this video. I love your videos I got lot of confidence after subscribing your channel.
Glad that the channel has helped you this much, thank you for your kind words and feedback means a lot to me
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.
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
Thank you so much bro
No problem, I am glad this was helpful
@codecat create one video for UITableviewDiffableDatasource and UICollcetionDiffable
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.
Thank you 😊
Glad it was helpful, do share the video with your iOS group and feel free to ask questions 👍
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
the error can be returned in the delegate function and can be displayed on the main thread on the view controller
Thank u
Welcome 🙂
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?
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?
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
Thank you Sir, for this amazing video with such a nice explanations. Can you do time test for different approaches?
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
@@CodeCat15 Welcome Sir
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?
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
the great explanation. Loved it..! I would like to know how we can unit test the HttpUtility class as this has the generic function.
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.
can you please tell how to write unit test as well for async await function. you can drive from TDD
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.
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?
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.
Thanks Ravi. This is really nice..
Just one query. Async/await runs on which thread main thread or global thread?
When you use async/await in Swift, the code runs on a separate concurrent thread managed by the system, rather than the main thread.
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)
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
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.
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)?
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
@@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?
I like async await but don’t like the do catch block everywhere
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
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
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.
Bro Push notification pe video banao na
Nice Tutorial !
one question do u know how to check Crashlytics Crash
This link will guide you out for the crashlytics logs
firebase.google.com/docs/crashlytics/test-implementation?platform=ios
@@CodeCat15 thanks ravi
Please tell me in English
What's your question? I will be happy to explain it for you.
😊