The Complete Guide Using SwiftUI MVVM Async Await & SwiftUI Error Handling: SwiftUI Tutorial

  Рет қаралды 9,083

tundsdev

tundsdev

Күн бұрын

Пікірлер: 79
@SBSanook
@SBSanook 3 жыл бұрын
I can honestly say this is the first video on async/await that really clicked with me - so good. Thanks so much, looking forward to more videos!
@tundsdev
@tundsdev 3 жыл бұрын
Thanks man, really appreciate it. I’ve got more interesting stuff planned/on the way 👀
@Collins01
@Collins01 2 жыл бұрын
Best ever swift networking tutorial I've seen on KZbin. Thanks man. Feels like using Flutter and Riverpod Mvvm pattern 💙
@tundsdev
@tundsdev 2 жыл бұрын
Thanks man glad you enjoyed it 👌🏾
@felixmatusinio6438
@felixmatusinio6438 Жыл бұрын
I think this might be the best practices for mvvm async/await in swiftui. I must subscribed!
@Spacer-l3j
@Spacer-l3j 10 ай бұрын
good stuff my bro people are charging money for this in deprh content we appreciate you my bro
@tundsdev
@tundsdev 10 ай бұрын
I appreciate that!
@gastongasquet3594
@gastongasquet3594 Жыл бұрын
Great great video about async await. It's the most complete video that also includes response and error handling. Terrific.
@tundsdev
@tundsdev Жыл бұрын
Glad you enjoyed man 🫡
@vojtechkalivoda8455
@vojtechkalivoda8455 Жыл бұрын
This video is actually super great example of Async/Await!!! 🔥🚀Also when u show us how to handle these edge cases with custom errors... It is PARADISE of learning hahaha Thanks a lot mate
@tundsdev
@tundsdev Жыл бұрын
You got it!
@StewartLynch
@StewartLynch 3 жыл бұрын
Another extremely useful and planned out video. Love it.
@tundsdev
@tundsdev 3 жыл бұрын
Thanks Stewart, I appreciate the support 👍🏾
@DougRobison
@DougRobison 3 жыл бұрын
I enjoyed this video. Thank you for putting it together. It's nice to see async/await finally make it to Swift to things can be simplified
@tundsdev
@tundsdev 3 жыл бұрын
Thanks, glad you enjoyed it 👌🏾
@douglasalexander4681
@douglasalexander4681 2 жыл бұрын
Thanks a bunch. You do a great job clearly explaining the material.
@tundsdev
@tundsdev 2 жыл бұрын
Thanks & glad you’re enjoying the content 👍🏾
@JoeVargas84
@JoeVargas84 2 жыл бұрын
Thank you for this! Very well explained! You have got yourself a new subscriber!
@tundsdev
@tundsdev 2 жыл бұрын
Thanks 👍🏾
@jimkurring11
@jimkurring11 3 жыл бұрын
Thank you for your continued stellar SwiftUI content. Great scope covered and explanations.
@tundsdev
@tundsdev 3 жыл бұрын
Glad you enjoyed it 🙌🏾
@ViktorJenei
@ViktorJenei 3 жыл бұрын
Great little summary m8!
@tundsdev
@tundsdev 3 жыл бұрын
Thanks glad you enjoyed it 👍🏾
@KhanhQuang-ff2ve
@KhanhQuang-ff2ve Жыл бұрын
I love you video mvvm with asyn ❤, you are wonderful
@paulallies
@paulallies 3 жыл бұрын
Informative, good code structure, and nicely explained. Thank you very much.
@tundsdev
@tundsdev 3 жыл бұрын
Glad you enjoyed it
@jontaylor1586
@jontaylor1586 3 жыл бұрын
Thanks. I’m digging into swift right now and I’m kind of surprised that it is only just now getting async await support. I guess my timing is good.
@DeirdreSM
@DeirdreSM 3 жыл бұрын
Your timing is very good, though it's not yet available in macOS builds (except on the beta Xcode when running on Monterey beta).
@ChrisKobrzak
@ChrisKobrzak 3 жыл бұрын
Thank you so much for putting effort into making all these videos on iOS development, Tunde 🙇‍ I'm relatively new to Swift and I've already learnt a lot! I really like your focus on practical examples, explaining your decisions as you go, solid naming conventions and unit testing. Just a small suggestion - you might want to consider recording the screen in a lower resolution to make the videos a bit more smaller screen-friendly. I know a phone is perhaps not the best tool for watching KZbin and it's great you've increased the font size in Xcode but I think scaling the resolution a bit would make your content that tiny bit more accessible.
@tundsdev
@tundsdev 3 жыл бұрын
Hey glad you enjoyed & thanks for the feedback. Surprisingly i’m not the most technical person when it comes to the technical recording stuff 😅 what are you referring too specifically if the screen resolution? Is the font too small? Too big? Or is it something completely different. Just so I can look into it next time and make some adjustments 👌🏾
@ChrisKobrzak
@ChrisKobrzak 3 жыл бұрын
@@tundsdev No worries at all, sorry for not making it more clear. Basically, go to `Settings -> Displays -> Display tab` select the `Scaled` Resolution option and choose one of the Larger Text icons. That's all there is to it. 👍
@timsonner
@timsonner 3 жыл бұрын
So cool, so much fun. great techniques and explanations. I would love to see how you would implement infinite scrolling in the list, the API returns only first 20 results (671 characters, so not truly infinite). Maybe throw in the searchable modifier and build out the UI a bit. Just thoughts. I'll figure it out, Tanks tunds! Great choice of API. Hyped!
@tundsdev
@tundsdev 3 жыл бұрын
Thanks man, I currently do have a video planned to discuss how i’d tackle infinite scrolling coming out soon so keep your eyes peeled 👀
@tundsdev
@tundsdev 3 жыл бұрын
Also I saw your previous comment too thanks again, not too sure why KZbin is deleting comments on my videos 🥴
@timsonner
@timsonner 3 жыл бұрын
@@tundsdev Nice, can’t wait. In your corner, cheering you on, keep on grindin! Thanks for the time you spend doing these videos, it’ll come back around.
@timsonner
@timsonner 3 жыл бұрын
@@tundsdev All good, sometimes I ramble, KZbin is probably doing some restructuring on the back end or something, maybe a bug somewhere.
@jontaylor1586
@jontaylor1586 3 жыл бұрын
On larger projects do you typically use a DI library or container or do you still manually create services and pass them through constructors?
@tundsdev
@tundsdev 3 жыл бұрын
I’ve saw DI libraries i.e SwiftInject but i’m yet to actually use them on a big project tbh. So I usually do it via constructers 👍🏾
@erdemsenol9642
@erdemsenol9642 3 жыл бұрын
Nicely explained, thanks. Can you do an in depth tutorial with Mapkit/CoreLocation? SwiftUI 3 seems to have some features to implement it easier.
@tundsdev
@tundsdev 2 жыл бұрын
Thanks 👍🏾 and noted
@syedmeer8972
@syedmeer8972 3 жыл бұрын
Which one is more better approach Asyn/Await or Combine ? please who see this comment must reply your reply is really helpful for me.
@tundsdev
@tundsdev 2 жыл бұрын
Both have their own purposes, it depends on your use case
@mr.getrighhttt3433
@mr.getrighhttt3433 2 жыл бұрын
This is a great tutorial. I'm curious though, how do I fetch an image from the URL using AsyncImage?
@tundsdev
@tundsdev 2 жыл бұрын
Thanks & I have a video covering this on my channel down below. kzbin.info/www/bejne/aIq5dnqcrZ2dhLc
@mr.getrighhttt3433
@mr.getrighhttt3433 2 жыл бұрын
@@tundsdev preciate that bro. I'm a native android dev looking to learn ios dev for my job. In Android, we have quite a few dependencies we can use for dependency injection. I noticed you manually injected yours here. Do you have a video on that as well?
@zeeshansuleman93
@zeeshansuleman93 5 ай бұрын
Create some more videos on unit tests and dependency injection
@liamchen6489
@liamchen6489 2 жыл бұрын
Thank you share .
@tundsdev
@tundsdev 2 жыл бұрын
Thanks 👍🏾
@RobertMcGovernTarasis
@RobertMcGovernTarasis 3 жыл бұрын
Thank you, useful video. My only comments are 1) any chance of putting the source up on GitHub? 2) I’m torn on the view knowing anything about the service class at all. I think I need to watch your MVVM project structure & im still need to using MVVM, but I’d have thought better to either have the service class internal to theVM (although the would make mock testing harder), or set up the view model with service class in top level App, and then pass that in as environment object … but then why would any other struct have access to the view model. 🤔
@tundsdev
@tundsdev 3 жыл бұрын
Hey Rob, 1) I will put it up, just at the moment i'm really busy with work & keep forgetting to do it. 2) The reason why I separated out the service class is because, when designing the architecture for my apps. I don't like tying the service code directly to view models. I prefer to treat service classes as individual units that can be swapped in and out of different view models. This is a really simple example that I did since I didn't wanna over complicate it. But what I would normally do is actually inject the view model into the swiftui view using the environment so the view would only have knowledge of the view model that it needs.
@congtuyeninh405
@congtuyeninh405 3 жыл бұрын
i want to use POST method with parameter, help me
@UnFuryYY
@UnFuryYY Жыл бұрын
Hey, is it safe to mark the ViewModel with @MainActor, wouldn't that cause the network request to be on the main thread?
@tundsdev
@tundsdev Жыл бұрын
Yes you can mark the view model with the annotation and all funcs and props would get on the main thread too. I just tend to mark my funcs individually just so i know which ones will update UI on the main thread 👌🏾
@Iwasee
@Iwasee Жыл бұрын
I didn't quite grasp the error handling part. Could you please clarify where the error message "The Internet connection appears to be offline" is coming from? In your service file, it seems like the only error being thrown is the one related to the 'invalidStatusCode.' So, how are you displaying this message on the screen since there isn't any in the error enum? Thanks in advance!
@tundsdev
@tundsdev Жыл бұрын
👋🏾 So basically line 21 in the fetch characters function the error you’re seeing isn’t my custom error its one that comes from URLSession when there is no internet. So this is where you get this internet message from its a built in error message from URLSession that is thrown 👌🏾
@Iwasee
@Iwasee Жыл бұрын
​@@tundsdev I understand now. So, all you have to do is use the 'throws' keyword in the function declaration to pass the error to the ViewModel, right? You don't need to use a do/catch block to handle and pass the error to the ViewModel ?
@tundsdev
@tundsdev Жыл бұрын
@Iwasee Yh so cos the function is marked as throws, whenever i use try it will catch that error
@Iwasee
@Iwasee Жыл бұрын
@@tundsdev Ok thank you for your time, really great tutorial :)
@tarun_reddy
@tarun_reddy 2 жыл бұрын
Love your videos! Quick question, i have a contacts view which shows a list of the users current contacts and a navigation link to see their pending friend requests. When they click on the nav link it takes them to a list of user requests which they can either accept or delete. The problem I have is that everything works correctly in the database but in the contacts view init i have the getContacts function so it doesn’t automatically update when a user accepts a request I have to go to another screen and then navigate back to it to see the updated list. Is there anyway I can reflect this change in real time?
@tundsdev
@tundsdev 2 жыл бұрын
Thanks, and what are you using for your database? CoreData? Firebase? CloudKit? You want to change your flow a bit here in you want to create a view model, rather than having a getContacts function you want to have a published property, so whenever you perform an action that should refresh the screen you want to call something to reassign a value to the published property to let SwiftUI know that, “Hey i’ve changed 👋🏾”
@tarun_reddy
@tarun_reddy 2 жыл бұрын
​@@tundsdev Im using firebase, and i'm also using published properties. Would you mind if i sent you a link to a quick loom video showing you my code and simulator so you can see what I mean and the problem that im facing
@tundsdev
@tundsdev 2 жыл бұрын
Hey man I actually have a firebase video that shows you how to react to changes to your database, you may want to check this out to see how I react to changes and update my UI using the firebase listener functionality. Hope this helps kzbin.info/www/bejne/a5ispox-o56hhcU
@tarun_reddy
@tarun_reddy 2 жыл бұрын
P.S. i shared your channel with the coding club here at Texas A&M!
@tundsdev
@tundsdev 2 жыл бұрын
Thanks man, hope you all enjoy 👌🏾
@Poroto2107
@Poroto2107 2 жыл бұрын
Amazing. Any chance you share the .xcodeproj shown in this video?
@tundsdev
@tundsdev 2 жыл бұрын
Thanks, and yep you can get all the source code for all my videos on my GitHub here github.com/tunds/KZbinResources
@Poroto2107
@Poroto2107 2 жыл бұрын
@@tundsdev Amazing. Thank you so much! Lastly, shouldn't you be throwing CharacterServiceError.failedToDecode if try JSONDecoder().decode(Song.self, from: data) fails for whatever reason? You're only throwing invalidStatusCode on that function. Not sure wether you just forgot to do so or Im just missing something? You declared the error on the enum but actually never threw it.
@tundsdev
@tundsdev 2 жыл бұрын
@@Poroto2107 yep lol i forgot to use it 😂😅
@Poroto2107
@Poroto2107 2 жыл бұрын
@@tundsdev Hah gotchu, no worries. Thanks for replying!
@indiekiduk
@indiekiduk 3 жыл бұрын
There seems to be a lot of bloat in this tutorial. Why are you using view model objects with SwiftUI? The whole point of its design is to let us use value types that can behave like reference types so using an object goes against that. And why are you using Combine’s ObservableObject with async\await?
@tundsdev
@tundsdev 3 жыл бұрын
I have to disagree with you with the term "bloat" and your other points. So let me break them down. 1. I'm using View Models objects since the title literally says "MVVM" aka Model - View - ViewModel which is a solid design pattern that I personally like to use when working with SwiftUI. In no point in the video do I state that MVVM is the only design pattern to ever exist or you can use, it's just the one I like to use & felt was good for this tutorial. 2. The reason why I have a view model object is to prevent my SwiftUI views from becoming bloated with loads of @State properties and variables, moving them out to a view model object allows me to separate concerns and also in the future I could unit test this view model directly to ensure it is behaving properly. 3. I'm using ObservableObject in relation to point two, the flow is my view starts my async task -> view model interacts with the service class -> service class returns data from the REST API -> view model holds data updates from the service -> view listens to published updates and reinvalidates itself with any necessary updates. 4. Like I said in the video this is a simple example, I feel like this is a good starting point for new devs using SwiftUI & MVVM who are looking for a good example. This comment that you wrote feels like don't agree/like MVVM rather than understanding why I did what I did lol.
@indiekiduk
@indiekiduk 3 жыл бұрын
@@tundsdev regarding 2, those are valid reasons for using a separate struct, not an object.
@indiekiduk
@indiekiduk 3 жыл бұрын
@@tundsdev regarding 3, ObservableObject and @Published with assignTo are features of Combine. If using async/await or task modifier then it’s all unnecessary because SwiftUI automatically stores the async context, a state object is not necessary.
@indiekiduk
@indiekiduk 3 жыл бұрын
@@tundsdev regarding 1, SwiftUI View structs hold the view data and thus are the view model already. Adding another layer of complexity of view model objects creates problems, e.g. strings that are using formatters won’t auto update if region settings change like they do if you use the Text struct with a formatter.
@tundsdev
@tundsdev 3 жыл бұрын
Again, i’d have to disagree. For me personally this would lead to you having a lot of State variables in your views, also this would be hard to unit test also. Separating out your properties into a view model, not only allows you to group your variables which will trigger UI updates. It allows you to also teat your view models to ensure they reinvalidate your views. Again if you’re someone who wants to store all your properties in State variables then more power to you. But me personally i don’t like this approach.
Симбу закрыли дома?! 🔒 #симба #симбочка #арти
00:41
Симбочка Пимпочка
Рет қаралды 6 МЛН
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 100 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 3,3 МЛН
Swift API Calls for Beginners (Networking) - Async Await & JSON
25:35
How do you go from completionHandler to async / await? 🤔
12:23
Vincent Pradeilles
Рет қаралды 2,6 М.
Authentication in SwiftUI App Using JSON Web Token (JWT)
54:38
How to handle errors in functions - Swift for Complete Beginners
11:16
3 MISTAKES to avoid when using Async / Await in Swift 😌
4:41
Vincent Pradeilles
Рет қаралды 12 М.