Swift Error Handling - Do, Try, Catch - iOS Interview Question Series

  Переглядів 50,853

Sean Allen

Sean Allen

6 років тому

The next topic in my series on iOS Interview questions explains error handling and the do, try, catch syntax in iOS and Swift. This iOS interview question was asked in a few interviews, so it's a good topic to learn. In this tutorial I walk though some basic error handling on a log in screen using the Do, Try, Catch syntax in Swift.
iOS Dev Courses - seanallen.teachable.com/
This is part of a series of videos about iOS interview questions in Swift. Check out the overview where I list and briefly discuss all the topics that are in this series:
• iOS Interview Question...
Source Code:
www.dropbox.com/sh/dhhy3kn1ql...
iOS Dev Courses:
seanallen.teachable.com/
Twitter:
Sean Allen - / seanallen_dev
Hired.com:
hired.com/x/1n01g
Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):
Paul Hudson's Hacking With Swift:
gumroad.com/a/762098803
Donny Wals - Combine:
gumroad.com/a/909014131
Mark Moeyken’s SwiftUI Books:
www.bigmountainstudio.com/swiftui-views-book/fzc51
Objc.io Books (Thinking in SwiftUI & Advanced Swift):
gumroad.com/a/656585843
Ray Wenderlich Books:
store.raywenderlich.com/a/208...
#swift #softwaredeveloper #iosdeveloper

КОМЕНТАРІ: 156
@seanallen
@seanallen 4 роки тому
Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ukposts.info/have/v-deo/hYN6mWiwbXyWxmw.html
@nadersaid2370
@nadersaid2370 4 роки тому
quick stupid question, i know this video is about Error Handling - Do, Try, Catch but what if i in this particular situation do it with a simple if else in loginButtonTapped to just show the appropriate alert? will it be a bad code?
@renagurbanovasenglish
@renagurbanovasenglish 14 днів тому
Thank you, even after 6 years, your code and teaching is still actual
@slash0t5
@slash0t5 4 роки тому
If I have to learn any difficult concept, I look up your videos. You explain it better than anybody else.
@seanallen
@seanallen 4 роки тому
Thanks for the kind words. Happy to hear they are helpful!
@bigmtnstudio
@bigmtnstudio 6 років тому
Awesome video! I like how you reinforced the "throw" keyword in there. 😃 The repetition makes it stick! Thanks, Sean.
@seanallen
@seanallen 6 років тому
Thanks Mark! I'm a strong believer in the power of repetition when learning... especially in programming!
@tactteam00
@tactteam00 6 років тому
I love this series for it's organization and simplicity. There are far too many hour long tutorials on these fundamental concepts. You explain it well and show people it's not as hard as many people make it out to be. Subscribed. Cheers
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Tactteem00. Glad to hear the videos are helping. More on the way!
@soyhenryxyz
@soyhenryxyz 6 років тому
Thanks for putting this example into context. Please continue to do your videos so that it's easier to understand where to use these programming concepts.
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, Henry! More videos on the way after the Thanksgiving Holiday
@javierv.5210
@javierv.5210 6 років тому
Dude every question I have about iOs, you have a video on it... thx A LOT!!! Happy new years!
@seanallen
@seanallen 6 років тому
Happy to help, Javier!
@chrisstromberg6527
@chrisstromberg6527 6 років тому
This was by far one of the best and most practical explanations of Do/Try/Catch I have seen!
@seanallen
@seanallen 6 років тому
Thank Chris! Glad you enjoyed it.
@tonyferber3252
@tonyferber3252 6 років тому
Thank you for the rapid explanation, Do, Try and Catch were confusing me. I am surprised to see no less than three Bang Operators !
@isaacclark9825
@isaacclark9825 6 років тому
Thanks for continuing your interview series.
@seanallen
@seanallen 6 років тому
You're welcome, Isaac.
@fikretsengul6214
@fikretsengul6214 6 років тому
Hey Mr. Allen, firstly, thank you for everything. I don't know how I discovered you has a wonderful, simple and understandable explanation. I'm a CS student in Ankara Bilkent University. I really wanted to learn swift but it was very complex until I find you. I cannot explain how happy I am, please continue to create these great videos ,series and keep it complete and simple. Thank you again. (sorry for the grammar mistakes)
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Fikret... More videos coming soon!
@ahmedMahmoud-zs5kn
@ahmedMahmoud-zs5kn 5 років тому
Best tutorial ever for swift error handling , really thank you.
@seanallen
@seanallen 5 років тому
Glad you liked it!
@NLBAMF
@NLBAMF 6 років тому
my favorite series ... thanks a lot ...
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Ahmed! I'll keep them coming!
@martinsin9775
@martinsin9775 5 років тому
Crystal clear of do try catch! Thank you!
@seanallen
@seanallen 5 років тому
Glad it helped, Martin 👍
@egesucu
@egesucu 6 років тому
Well I'm a beginner developer and I really needed to see some videos about iOS development and etc. I found your channel and enjoying so far. Thanks man :)
@seanallen
@seanallen 6 років тому
Glad you're enjoying it Ege! Feel free to reach out with any questions if you get stuck on something.
@johntamch
@johntamch 6 років тому
Another great video from this series! Detailed and yet easy to understand. Thanks.
@seanallen
@seanallen 6 років тому
Glad you enjoyed it, John!
@Reel_Sober
@Reel_Sober 6 років тому
Love your videos man! You are putting out some great content. Thanks for your time and effort.
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Art! It means a lot.
@SivarajahPranavan
@SivarajahPranavan 5 років тому
Excellent example for "throw"
@Sasan_Soroush
@Sasan_Soroush 5 років тому
Your videos are just what i needed all the time thank you
@seanallen
@seanallen 5 років тому
Happy to help, Sasan 👍
@myrondulay8628
@myrondulay8628 3 роки тому
Very useful. Thanks Sean!
@brandonfong9998
@brandonfong9998 4 роки тому
thanks for making these videos!! could you do one on regular expressions in swift and how to use them to validate data users put in text fields?
@choofie
@choofie 6 років тому
Nice explanation Sean! I’m really enjoying your videos! I know it’s crystal clear to everybody, but please note that the magically code that actually logs you in will be performed asynchronously in the background (obviously). So make sure to handle the successful login request properly, and put your transition code there, instead of simply putting them the next line right after try login(). Otherwise the control will be given back to your do block, where the remaining code will be executed before the login response arrives.
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Mate! You are correct. I didn't go into all this because I didn't want to distract from the point of the video too much, but it is a good clarification.
@yourmovies3724
@yourmovies3724 3 роки тому
Good job! I finally got it
@jyotinkarpandey
@jyotinkarpandey 5 років тому
awesome stuff. thanks a lot for this content :)
@karunakarbandikatla9462
@karunakarbandikatla9462 6 років тому
Short and simple... Superb :)
@seanallen
@seanallen 6 років тому
+Karunakar Bandikatla Glad you enjoyed it.
@yogeshnewpanay8613
@yogeshnewpanay8613 Рік тому
bro dont have words you are just great at explaining some people are flaunting their talent by making complex code i agree they know some good stuff but you make swift look easy #highlymotivated
@lowhybrid
@lowhybrid 2 роки тому
Great video. Thanks
@taylormaxwell1277
@taylormaxwell1277 4 роки тому
Another excellent share, thank for your the clear explanation
@seanallen
@seanallen 4 роки тому
Thanks for watching all these Taylor. Glad they were helpful.
@abhilashmathur8390
@abhilashmathur8390 6 років тому
Nice Video!! Can you explain what is the difference between throws and rethrows?
@saad2execute
@saad2execute 6 років тому
Great tutorial, thanks a lot :)
@seanallen
@seanallen 6 років тому
Glad you liked it, Saad!
@SuperMarucca
@SuperMarucca 6 років тому
Very helpful!!!!! Thank you very much! :)
@seanallen
@seanallen 6 років тому
Happy to help, Fabio. You're very welcome.
@brandonb6175
@brandonb6175 6 років тому
Great Video Sean!
@seanallen
@seanallen 6 років тому
Thanks Brandon!
@karenkarapetyan6332
@karenkarapetyan6332 6 років тому
Hi Sean. Thank you for the great tutorial. Is there a way to throw nothing in a function that throws? e.g (I don't want to create class or enum inherit from Error and return that object.)
@saurabhtripathi5718
@saurabhtripathi5718 4 роки тому
hey please make more videos on interview question and answers.
@guillaumeramey
@guillaumeramey 5 років тому
I love the Alert handling, well done. But I discover the "class func", what is it ?
@nileshpol5098
@nileshpol5098 6 років тому
Great.. I’d expect if you include odd scenarios too, at the end of each video
@wensmusic8636
@wensmusic8636 2 роки тому
Hi thank you for this video, I have never seen both enum error cases, and a do try catch being used in the same function, were you just giving an example of how to use both, or do you usually do that only when there is a throw included? I ask because I imagine that if there is a throw included inside of the function, we only really need to use a do try catch block and can print out the error to do displayed to the user and do not need the enum cases? does this make sense ? Which is preferred?
@sudebsarkar21
@sudebsarkar21 6 років тому
Thanks Sean, This video is very helpful , Can you please make sure that if their is any way to write all error cases in another swift file ? If it is possible, please give an example as I am new in swift so I am facing some problem to write this code.
@mohsinkhan845
@mohsinkhan845 5 років тому
Very helpful video
@seanallen
@seanallen 5 років тому
Happy to help, Mohsin 👍
@donathmm3881
@donathmm3881 4 роки тому
Thank you!
@seanallen
@seanallen 4 роки тому
Happy to help, Donat!
@KulturanCov
@KulturanCov Рік тому
The thumbnail looked like a Nike commercial lol (do... try... catch)
@barche75
@barche75 6 років тому
Awsome) Thanks a lot!
@seanallen
@seanallen 6 років тому
Glad you enjoyed it!
@pravin1015
@pravin1015 6 років тому
hey can u explain how to use nspredicate to filter strings
@Asif_Siddique332
@Asif_Siddique332 5 років тому
Awesome!​
@danzaverdk
@danzaverdk 5 років тому
Hi Sean, I'm a beginner in Swift, and I'm wondering how did you able to use the function in class Alert without instantiating it? or i just overlooked it somewhere? sorry for newbie question..
@ShashiKumar-rn3uz
@ShashiKumar-rn3uz 6 років тому
Hi Sean .your videos are awesome .teaching skills are great.Please upload some videos for Core Data,Fetch Controller,Fetching large no of records from API ,Writing into Core Data and Displaying them into Table View concurrently.Thanks In Advance.
@seanallen
@seanallen 6 років тому
Hey Shashi, Thanks for the kind words! Glad you're enjoying the channel. As for Core Data tutorials, I probably won't be doing that anytime soon. I've never used it, and I just haven't seen the adoption in my experience to make it worth while. From my experience here in Silicon Valley, it isn't used all that often on production level projects. (Don't get me wrong, I'm not saying it's NEVER used... just pretty rare).
@ravimaharjan2744
@ravimaharjan2744 5 років тому
Is there a way to define error messages in enum and just use one catch and throw relevant error message ?
@fakeme87
@fakeme87 6 років тому
Thanks for all your work on your channel! Quick question: could we instead of catching each error separately have a single ´´´catch let error { ... } ´´´ and do a switch on the error property inside?
@seanallen
@seanallen 6 років тому
I've actually never implemented it that way, but that sounds viable. Huge disclaimer... I haven't researched that and could be wrong. I would need to dig into it a bit more, but off the top of my head, it sounds alright.
@radoslavradev8477
@radoslavradev8477 6 років тому
Beautiful !
@seanallen
@seanallen 6 років тому
Thanks Radoslav!
@nightlynewsreview5076
@nightlynewsreview5076 4 роки тому
Great video, love the speed of your speech. I hate slow talkers!
@seanallen
@seanallen 4 роки тому
Glad you liked it! I get a lot of comments that I talk too fast.
@erickramones2167
@erickramones2167 4 роки тому
is it possible to put the enum in a separate file? I just started learning swift.
@GulamALI-ni4ot
@GulamALI-ni4ot 6 років тому
love u brother from another mother !!
@seanallen
@seanallen 6 років тому
Glad you liked it!
@gillesashley9314
@gillesashley9314 2 роки тому
Bro u are too good. How long have u been coding swift ?
@seanallen
@seanallen 2 роки тому
Since early 2015
@gillesashley9314
@gillesashley9314 2 роки тому
@@seanallen wonderful. How many hours a day? Anyways I followed u on Twitter.
@thatmark88
@thatmark88 6 років тому
Hey Sean, very nice tutorial, just download code . I wonder how did you setup the constraint of the all ui elements, did you setup constraint for each ui element, or you use suggested constraint for all. Maybe a tutorial about view constraint next time?
@seanallen
@seanallen 6 років тому
I set up the constraints for each UI element individually in the storyboard. A how to video for constraints is high on my list of videos to make.
@AriMunandar
@AriMunandar 6 років тому
Hi Sean, What's best architecture for developing longterm product? Now i'm using Viper for my product.
@seanallen
@seanallen 6 років тому
I've really only used MVC, and payed around with MVVM so I'm a bit biased towards MVC. My thought's on this subject are that it's a personal preference and would depend on your team and the project. Certain architectures may be better for certain projects.
@yaroslavlvov9481
@yaroslavlvov9481 6 років тому
Nice! But forgot to mention the try! And try? There some cases to use it as well
@seanallen
@seanallen 6 років тому
Hey Yaroslav, thanks for the feedback. I didn't forget about Try! and Try? I just decided no to discuss them for a couple of reasons. 1. The video was already getting a little long 2. The topic of the video is Error Handling in a Do, Try, Catch block. When using Try! and Try?, you are essentially choosing to not handle the errors so it wasn't 100% on topic. The combination of those 2 reasons are why I decided to cut that topic.
@alvolante2990
@alvolante2990 3 роки тому
Really helpful vídeo man I Man doing a Udemy course but they don’t explains this that well
@seanallen
@seanallen 3 роки тому
Glad you like my teaching style. These are some of my older videos and I've actually gotten a lot better. If you're not happy with Udemy courses, I started creating courses at seanallen.teachable.com if you want to check them out. You can watch the first ~10% of each one as a free preview.
@NikeTao
@NikeTao 6 років тому
Is the isValidEmail extension written in a mix of Swift and Objective C? The emailFormat looks akin to it
@seanallen
@seanallen 6 років тому
Nope, it's all in Swift. The weird syntax you see is the Regular Expression stuff. But it's all in Swift.
@murad3460
@murad3460 6 років тому
Hey! Do you suggest using storyboards or doing everything programmatically in big projects?
@seanallen
@seanallen 6 років тому
I think this comes down to personal preference. They both have their pros and cons in my opinion. Storyboards can be a pain when working with a team due to merge conflicts and code review. However, I prefer using Storyboards because I don't like "clutter' in my code. And all the UI and auto layout code can clutter up a file in my opinion. But again, it's personal preference. If you're just learning, you'll learn a lot more by doing your UI in code. However, once you understand what's going on, doing your UI in storyboard is cleaner in my opinion.
@thebrandontyler
@thebrandontyler 6 років тому
Can I ask about the regular expression for the email validation? I see that [A-Z0-9a-z._%+-] means any of those characters in the brackets and the + means one or more times, then you have the @ symbol which makes sense. After the @ symbol, you have [A-Za-z0-9.-]+ which is basically the same thing as above without a few of the special characters. My question starts here: \\. I know that \. means "." because it has to escape, but why the extra "\"? I think I also understand the end: [A-Za-z]{2,64} means A-Z and/or a-z anywhere from 2 to 64 times, right? Thanks! This is really helpful; it's the first time I've seen regular expressions in Swift and honestly didn't know it was possible before this video.
@seanallen
@seanallen 6 років тому
Hey Brandon, I'm not gonna lie and act like I fully understand all the ins and outs of regular expressions. It's a tricky topic to wrap your head around. I got this code snippet from a senior iOS dev a couple years ago and have been using it every since. Sorry I couldn't be of more help, but I would have to do more research before answering correctly.
@dev888www6
@dev888www6 5 років тому
Hello guys ! Did you find the answer to this question? Thank you!
@edwincreator2855
@edwincreator2855 6 років тому
why there is a double if statement, why if else is not use instead ?
@OnionKnight541
@OnionKnight541 3 роки тому
The question I'm sure many have is: why use this instead of *if / else* statements? What is the actual advantage of using Do Try Catch?
@salvatorecastelluccio4901
@salvatorecastelluccio4901 5 років тому
When an iOS job applicant is at an onsite interview are they generally allowed to bring a paper notebook or iPad to use as a reference during the coding exercises? (algorithms excluded)
@seanallen
@seanallen 5 років тому
I've never seen that allowed.
@sophiemccarthy1341
@sophiemccarthy1341 6 років тому
Hey Sean. As a beginner, I'd like to ask you something. When you started learning, did you focus on the language alone (swift) and OOP concepts, and then moved to more core issues like algorithms? Is there any tip you could give me as a beginner? What would be the best way to learn swift and get better understanding of OOP?
@seanallen
@seanallen 6 років тому
Hey Sophie, I started learning the language and OOP concepts first. I didn't get around to data structures and algorithms until it was time to apply for an iOS Developer position. And that was mainly because you need to know that stuff more so for the interview than the actual job. So as a beginner, I would definitely focus on learning Swift, the language, as well as basic OOP principals. I would start by doing tutorials on raywenderlich.com and then start building small apps on your own. I'm a big believer on "learning by doing", and you'll learn a lot when you try to build your own app idea.
@tonyferber3252
@tonyferber3252 6 років тому
I am learning too, one thing I think is important is to be able to speak in the Swift language and not use terms like "this", "that" and "stuff". Everything has it's own name like "variable", "operand", "nil coalescence" etc..
@Olden2610
@Olden2610 6 років тому
Hi Sean! Have a question: In case - we don't need error (wich in catch block) - can we use something like: let isLoggedIn = try? login() ?? false (login() returns true in case of success)?
@seanallen
@seanallen 6 років тому
I'm not sure of the exact code you're looking for, but in general, if you're not going to handle the error then you don't need to full do, try, catch block;
@Olden2610
@Olden2610 6 років тому
Actually - in case of some code throws an error - you have to deal it with do try catch block.
@rahulbandal9185
@rahulbandal9185 6 років тому
Nice video again,sean how we can implement pager in ios like android
@seanallen
@seanallen 6 років тому
I've never used an Android phone, so I'm not sure what behavior you're talking about.
@rahulbandal9185
@rahulbandal9185 6 років тому
Its Like tab bar in ios ,Match with watsapp app what they used instead of tab bar in android
@adityabantwal
@adityabantwal 6 років тому
It is kind of like a scroll view. link-developer.android.com/training/animation/screen-slide.html.
@seanallen
@seanallen 6 років тому
Ok, now I get it. Looks like a scroll view or UIPageViewController in iOS.
@bartoszdolewski4915
@bartoszdolewski4915 6 років тому
If this is real life situation then IF statements would be changed for GUARD, right? Is there a practical difference between those two ?
@seanallen
@seanallen 6 років тому
It would depend on the situation. The main reason you would use GUARD is if you wanted to exit the function as a result of the "failed" guard. Guards provide an "early exit" from the function if you want it.
@ladahavlik8054
@ladahavlik8054 6 років тому
Hello Sean, if I understood try catch is only for throwable methods. But how I can catch error from nonthrowable function or method. Example: let a = String(data: someData, encoding: .utf8) . Some times it it crash and application crash. Can I catch this error? Thank you.
@seanallen
@seanallen 6 років тому
In the example you provide, functions like that from Apple often return an optional. The reason it's crashing for you is because you're not unwrapping the optional correctly. So when the result of that function is nil, you'll get a crash.
@adityabantwal
@adityabantwal 6 років тому
Hi, Can you provide a starter project along with full source code.
@seanallen
@seanallen 6 років тому
That's a good idea, Aditya. I'll start doing that.
@stevengao8345
@stevengao8345 6 років тому
hello, you variable isValidEmail : bool , then put the { } , what is this, you add a closure behind it, so it will be executed everytime ? sorry i am a newbie, see this sometimes, don't know wut it is officially called ?
@seanallen
@seanallen 6 років тому
This is called a "computed property". Which means the property isn't a set value, like for example "var myNumber = 1". In that case, "myNumber" is always 1 (unless you change it). In a computed property, the value needs to be figured out. It's figured out by whatever logic you write in the {}
@stevengao8345
@stevengao8345 6 років тому
thank you, very clearly explained.
@oTarrell13o
@oTarrell13o 5 років тому
Sean, what your methodologies when coding? I feel that some times I get lost in code because I don't have a general sense of direction when a problem may arise. I'm trying to get better, typically would write python scripts but now that I am getting into this type of development and using more and more files such as classes to fulfill the application its hard planning. It can kinda be discouraging but I feel like its something common and all you need is the right sense of direction when stuck.
@seanallen
@seanallen 5 років тому
I know what you're saying. It was overwhelming at first. To be honest, there's not really an easy answer. It's something I've developed over a couple years, and I'm still building. (Talking about my methodologies). They are constantly evolving and improving. Coming up with how you like to structure your apps is something that comes with time an experience.
@aniltodakar6449
@aniltodakar6449 6 років тому
Sir, What is a helper method?
@seanallen
@seanallen 6 років тому
Basically a method that takes a small tasks and puts it into it's own method. Even tho this is just a 30 second preview, the video description and transcript should give you an idea: teamtreehouse.com/library/helper-methods
@aniltodakar6449
@aniltodakar6449 6 років тому
can you make a video on helper method please.
@AshutoshSingh-vm6jy
@AshutoshSingh-vm6jy 6 років тому
Hey Sean why we use " static var"
@seanallen
@seanallen 6 років тому
Here's a great, concise explanation: www.hackingwithswift.com/read/0/18/static-properties-and-methods
@AshutoshSingh-vm6jy
@AshutoshSingh-vm6jy 6 років тому
Thanks
@ben6
@ben6 2 роки тому
What is really confusing about Swift syntax here is the implicit `error` inside the catch block, when you might already have an error defined above.
@lukewazea2k7
@lukewazea2k7 6 років тому
imo it would be better to handle the title and message of the error inside the error enum, that way you can just call the alert message once. Nevertheless, probably the best video I've come across on error handling.
@seanallen
@seanallen 6 років тому
Good point. Thanks for the kind words, Luke!
@sashakolsky
@sashakolsky 6 років тому
Can you give me an example of how would you pass both title and message with enum value? I can add an associated rawValue, but only of a simple type (Int, String, Bool), but not a dictionary like: [String:String] Here is the only thing I could come up with, which is a bit ugly, imho: enum LoginError: String, Error { case incompleteForm = "Incomple Form:Please fill out both email and password fields" case invalidEmail = "Invalid Email Format:Please make sure you format your email correctly" case incorrectPasswordLength = "Password Too Short:Password should be at least 8 characters" } do { try login() // Transition to next screen } catch let error as LoginError where [.incompleteForm, .invalidEmail, .incorrectPasswordLength].contains(error) { let errorMessage = error.rawValue.split(separator: ":") Alert.showBasic(title: String(errorMessage[0]), message: String(errorMessage[1]), vc: self) } catch { Alert.showBasic(title: "Unable To Login", message: "There was an error when attempting to login", vc: self) }
@fikretsengul6214
@fikretsengul6214 6 років тому
I'm also curious about this question. If Mr. Allen can enlighten us it would be great.
@emrahkorkmaz3991
@emrahkorkmaz3991 6 років тому
You must use tuples, and you can man.
@smarter2610
@smarter2610 4 роки тому
sean, when variable looks like yours : var isValidEmail : Bool { ..... return ..} Is this a computed property or what?
@seanallen
@seanallen 4 роки тому
Yup, that's a computed propery
@smarter2610
@smarter2610 4 роки тому
@@seanallen Anyway, do you think that trying to get into ios carreer is a good idea in present times? I want to try send come resume in next month in my country(Poland). I don't know how market look like. Unfortunately i don't see so many offers;/ at least in my area
@chaudhryumair5380
@chaudhryumair5380 5 років тому
great
@seanallen
@seanallen 5 років тому
Thanks!
@BRBallin1
@BRBallin1 4 роки тому
Great content, but feel like they should be supplemented with examples of how they are applied within the context of iOS development similar to this video
@seanallen
@seanallen 6 років тому
Have a question about the Do, Try, Catch syntax? Leave a question below!
@subinrevi1
@subinrevi1 6 років тому
Hey Sean, you mentioned that we use do,try,catch in cases where the function outputs some error. What is the advantage of using do,try, catch over an "if else" in this case. Is it that it makes the code looks better of is there some benefit in actual speed of execution or something like that ?
@yogeshnewpanay8613
@yogeshnewpanay8613 Рік тому
bro i have a request that i feel that once in a week for an hour you should interact with us for our queries or doubt if you can give one hours of your precious schedule it will be pleasure for us waiting for yours zoom , google meet link
@abdurehmanfarooq9845
@abdurehmanfarooq9845 Рік тому
using api is not that easy i am stuck on it can you explain it for us as i am a beginner
@seanallen
@seanallen Рік тому
I have a video coming out in a few weeks called "Network Calls for Beginners". Keep an eye out...
@abdurehmanfarooq9845
@abdurehmanfarooq9845 Рік тому
@@seanallen thanks in advance
@ssaguiar
@ssaguiar 6 років тому
Thanks for your video. I wih to ask one thing: How can I implemente an error handling in the code below? Presently it doesn't work because it doesn't throws errors. It gives these warnings, in xcode: No calls to throwing functions occur within 'try' expression and 'catch' block is unreachable because no errors are thrown in 'do' block Thank you for any help, if possible. DispatchQueue.main.async { do { self.name.text = MyAccountViewController.nameofuser self.email.text = MyAccountViewController.email self.sessions.text = "\(MyAccountViewController.active_device_sessions)/\(MyAccountViewController.max_devices_sessions)" self.plan.text = MyAccountViewController.userplan try MyAccountViewController.used_disk_space = ByteCountFormatter.string( fromByteCount: Int64(MyAccountViewController.used_disk_space)!, countStyle: ByteCountFormatter.CountStyle.file ) try MyAccountViewController.max_disk_space = ByteCountFormatter.string( fromByteCount: Int64(MyAccountViewController.max_disk_space)!, countStyle: ByteCountFormatter.CountStyle.file ) try self.space.text = "\(MyAccountViewController.used_disk_space)/\(MyAccountViewController.max_disk_space)" } catch let e { debugPrint("failed to get user data: \(e)") } }
@seanallen
@seanallen 6 років тому
Hard to say just by looking at the code in a UKposts comment. I'd have to play around with it in Xcode to debug it.
@gjermundification
@gjermundification 6 років тому
This video has some gems 0:44, 1:55, 10:15 and maps this up to the GUI here: 12:18 and as an added bonus "Feel free to steal this:" 11:39
@seanallen
@seanallen 6 років тому
Thanks for the kind words, Gjermund.
Swift Optionals - How to Unwrap (real examples)
14:20
Sean Allen
Переглядів 10 тис.
iOS Concurrency and Threading - iOS Interview Question - Swift
7:50
Sean Allen
Переглядів 104 тис.
Їжа Закарпаття. Великий Гід.
1:00:29
Мiша Кацурiн
Переглядів 461 тис.
🐩🐕
00:25
Янчик
Переглядів 2 млн
How to handle errors in functions - Swift for Complete Beginners
11:16
Merge Sort - Swift Tutorial - iOS Interview Coding Challenge
12:42
Sean Allen
Переглядів 23 тис.
How to use Lazy in Swift
9:56
Sean Allen
Переглядів 38 тис.
Memory Leaks in iOS: Find, Diagnose, & Fix (2022)
12:44
iOS Academy
Переглядів 44 тис.
Swift - Bounds vs. Frame - iOS Interview Question
8:00
Sean Allen
Переглядів 54 тис.
UIViewController - Lifecycle | Swift | viewDidLoad
7:57
Sean Allen
Переглядів 39 тис.
Photo Changing Replace And Edit Backgrounds 65mn With These 10 Tips
0:53
Irfan AN Tech
Переглядів 260 тис.
Iphone yoki samsung
0:13
rishton_vines😇
Переглядів 9 млн
Робот зарядка на 65W🤖
0:36
serg1us
Переглядів 1,6 млн
I7 2600K тест в играх и сравнение с AMD Ryzen
17:53