Build A Reusable Networking Layer In Swift with Generics

  Рет қаралды 3,267

tundsdev

tundsdev

Күн бұрын

Build A Reusable Networking Layer In Swift with Generics
🤙🏾 Subscribe to the tundsdev KZbin channel
www.youtube.co...
⏭ Next Video
Using MVVM to Create our PeopleViewModel
• Using MVVM to Create o...
⏮ Previous Video
What is MVVM For Beginners (What is MVVM?)
• SwiftUI MVVM Explained...
Ready to level up your SwiftUI skills?🚀
Learn how to tackle take-home projects in SwiftUI, nail interviews, and more with this FREE course!📚
This KZbin playlist teaches you everything you need know to land your first iOS role 🫂
📹 • SwiftUI Take Home Proj...
In this video, we'll bring together our knowledge of generics and look at building a singleton class that we can use to easily help us with networking in our iOS applications.
We'll talk about how building this class will help us out with making our networking code easier.
Communicate Between Views In SwiftUI With Closures, Understand Swift Closures & @escaping In Swift
• Communicate Between Vi...
Understand Classes vs Structures in Swift in Under 10 minutes (iOS Interview Question)
• Understand Classes vs ...
SwiftUI Easy MVVM API JSON Example with URLSession (URLSession JSON API Example)
• SwiftUI MVVM Swift Exa...
What is a REST API? (REST API Explained for beginners)
• What is a REST API? (R...
How To Use Codable in Swift (Codable Swift)
• How To Use Codable in ...
Advanced Codable in Swift
• Advanced Codable in Swift
How To Use Postman To Test A REST API (Postman Tutorial)
• How To Use Postman To ...
SwiftUI iOS Take Home Test Resources
github.com/tun...
SwiftUI iOS Take Home Test Course (Learn SwiftUI Online For Free, SwiftUI Free Online Course, iOS Dev Job Interview Practice - Take Home Project)
• SwiftUI Take Home Proj...
👦 SwiftUI Sessions - Beginners (Learn SwiftUI Online For Free, SwiftUI Free Online Course)
• Learn SwiftUI From Scr...

Пікірлер: 25
@coolcodingdad
@coolcodingdad Жыл бұрын
It has to be the best walk-through I've seen on KZbin about making a network request. Such a thorough step-by-step process that is clearly explained and executed. Great job, Tunds! 👏😃
@tundsdev
@tundsdev Жыл бұрын
You're very welcome!
@KimbrellBrad
@KimbrellBrad 2 жыл бұрын
I use a NetworkManager with both a Combine and a Completion Handler version that is almost exactly like this one. It is always helpful to review the code as I seem to pick up new tidbits every time I listen to someone else describe the process. Thanks for the clear and consise explanation!
@tundsdev
@tundsdev 2 жыл бұрын
Glad you enjoyed it, wait until we refactor it to use Swift Concurrency 👀
@vishwa.ravi3001
@vishwa.ravi3001 2 жыл бұрын
This was really helpful thanks.
@tundsdev
@tundsdev 2 жыл бұрын
Glad you enjoyed it 👌🏾
@paulpenketh6057
@paulpenketh6057 2 жыл бұрын
Never seen ~= before. Very useful, thanks!
@tundsdev
@tundsdev 2 жыл бұрын
Glad you found the video useful 👌🏾
@larschristiansen3136
@larschristiansen3136 2 жыл бұрын
This episode has been very beneficial for me. I think that I had some of the pieces, but this put it all together. And a a bonus, on the topic of @Escaping a missing light was lit for me. Thank you so much for the episodes that are all of interest to me. A question you add an x to the the absolute string to provoke an error? But the error is misleading pointing to a decoding error, when I would be much surprised if any data was actually fetched. I believe that invalidURL only cas an error if it cannot unwrap, but not if the url points to nowhere. 😆One could search for the decoding error for some time.
@tundsdev
@tundsdev 2 жыл бұрын
Thanks and glad you enjoyed the video, in terms of the url. Yep that error (invalid url) would only be thrown if the url was nil i.e. the string url was just completely wrong in terms of it structure and it failed to create it 👌🏾
@Ravikanth_007
@Ravikanth_007 9 ай бұрын
Great tutorial 🎉
@tundsdev
@tundsdev 9 ай бұрын
Thank you! 😊
@inalbansal
@inalbansal 2 ай бұрын
In the above response code - The range (200...300) should be (200..
@tundsdev
@tundsdev 2 ай бұрын
200 will be included in this range, as well as 300 which is fine when checking for a successful status code
@rtorcato
@rtorcato 2 жыл бұрын
Have you used Alamofire? Is it worth building your own networking manager when Alamofire has so many features
@tundsdev
@tundsdev 2 жыл бұрын
I have used Alamofire before, but Alamofire is actually built using URLSession under the hood 😉, another benefit of doing is learning how to write networking code without being dependent on a lib, as well in terms of executing a request do you really need a whole lib? I agree alamofire is good but for most cases where you just need to make an API call to fetch some data writing your own code will give you better understanding of how networking & threading works 👌🏾
@EmanNollase
@EmanNollase 2 жыл бұрын
awesome tutorial!!, few questions: 1) What if the api return an array of objects [], how you can handle it generically? 2) some api server has some payload data too when there is an error occurred? like jwt error, 401 and so on, how do you handle this error with some payload from the server? because we may want to display the server error message too. Thanks
@tundsdev
@tundsdev 2 жыл бұрын
Thanks, And to answer your questions, 1) So if you wanted to handle an array of objects, they you'd just need to declare it as an array of types i.e. if we wanted to decode an array of users it would be (..., type: [User].self) 2) So to handle this you'd want to write some logic for when we check the status code, so if it the response was a 401 then you could throw an error similar to what I do in the guard statement, where I check the status code and throw the invalid status code. You'd put in extra logic to handle any custom errors here. Hope this helps 👌🏾
@EmanNollase
@EmanNollase 2 жыл бұрын
@@tundsdev thanks. yes we can do it like this [T].self, but in your method it only return T, do we need to write another method to handle array of objects?
@tundsdev
@tundsdev 2 жыл бұрын
T doesn’t mean that its a single object it means it can accept any type since its just a placeholder so you could have a single or array of a type. I’ve just whipped up an example showing you how you can use both an array of objects and a single object in a gist 👌🏾gist.github.com/tunds/d6e9dd188e54b962c11ef34a3ad3b941
@shivaskanthan6144
@shivaskanthan6144 2 жыл бұрын
Any chance of a concurrency version of this video?
@tundsdev
@tundsdev 2 жыл бұрын
Yep it’s coming up very soon in the course where we refactor this to use Swift Concurrency 👌🏾
@shivaskanthan6144
@shivaskanthan6144 2 жыл бұрын
@@tundsdev looking forward to it!
@tundsdev
@tundsdev Жыл бұрын
@@dotinsideacircle So there is a video in this course where we refactor it that you should see in this course 👍🏾
@tundsdev
@tundsdev Жыл бұрын
I just replied to your previous comment with it… kzbin.info/aero/PLvUWi5tdh92yKhrDU_E04WtfbNO4wP1YH
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 337 М.
Human vs Jet Engine
00:19
MrBeast
Рет қаралды 68 МЛН
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 87 МЛН
№37 - Generics в Swift | Прошел этого босса прошел Swift!
1:47:57
В’ячеслав Білий
Рет қаралды 9 М.
SwiftData Migrations | SwiftData Tutorial | #11
32:24
tundsdev
Рет қаралды 4,5 М.
How to use Protocols in Swift | Advanced Learning #15
28:37
Swiftful Thinking
Рет қаралды 16 М.
How to use MVVM with Async Await | Swift Concurrency #14
11:42
Swiftful Thinking
Рет қаралды 10 М.
Swift Generics for Beginners - Eliminate Code Duplication
10:37
Sean Allen
Рет қаралды 20 М.