How to safely unwrap optionals in Swift with if-let and guard statements | Bootcamp #47

preview_player
Показать описание
In almost every application there are cases where you will declare variables as optional. In Swift we declare a value as optional be using the ?. When we do this, we are telling Xcode that this variable has the potential to be nil (or without a value). Therefore, when we go to use that variable in our code, we need to safely check whether or not it really has a value at that time. Two of the smartest and safest ways to safely "unwrap" these optionals is be using 'if let' and 'guard' statements. In this video we will learn both! It should be noted that both of these methods are MUCH safer than explicitly unwrapping optionals by using the ! symbol (avoid this!).

🤙 WELCOME BACK 🤙

Рекомендации по теме
Комментарии
Автор

It’s great that you’re teaching good coding habits.

AZMerf
Автор

a clear explanation of if let and guard. This helped me a lot. Thank you.

ovadianyc
Автор

Your videos are really shortening the learning curve for me; thank you!!

Jump_Jay
Автор

Nick, you are god-blessed teacher :) Thank you for this exact series of tutorials and for all that playlists that i'm gonna go through on your channel. Thank you very much

SemRosto-bz
Автор

Wonderful video. Love guard example. I saw another example using enums to display error using enum value. That was also pretty cool. U throw error and print(error) which is the enum value (out of paper, toner error, etc)

bbulliard
Автор

Hello Nick, another great video, A year ago I started to learn IOS, maybe you will not believe but today I really get the logic behind IF LET & GUARD.

barsciftci
Автор

The effect "Safe coding = great coding 🥳" just made me smile... xd

Thx Nick.

radekjenik
Автор

Oh, thank you again. Very important topic. And now I realize it really better. Thanks a lot!😊

nevemra
Автор

Great video as always! Thank You for your work!!!

Filwoj
Автор

Love the video! Rookie question... do guard let statements only work inside of a Function() or can you do it outside a function? I was seeing a trend on stack/google leaning towards only using guards inside of functions. Thank for all your effort to educate!

Yourboye
Автор

As usual, enlighten video!. Thanks a lot. Now, how to know which one is better to use (let or guard)?

lautarob
Автор

Great video. Following all your videos along!

TheSpiralnotizblock
Автор

Thank you for such a good tutorial series!

Автор

Thanks Nick! I enjoy every your video!

ShowMeLova
Автор

Keep up the excellent work, God bless on you for this effort

muhammadusman-vcre
Автор

it would be helpful if you add video with quick review of documentation and resources that iOS developer needs to keep on hand

dofaminx
Автор

amazing tutorial. I fully understand these now. Thank you! sub'd

FNMonsters
Автор

Using guard let allow us to use the code outside of the {} but in the if let you need write the code inside the brace{}..it depends on the code requirements which one we should use.

emdutt
Автор

Nick Thank you very much for your helpful tutorial

magedmohmed
Автор

I may be nitpicking here. But just to clarify, when we say:
@State var currentUserID: String?
@State var displayText: String?
Swift will automatically initialize those variables to nil values, doesn't it?
So saying this:
@State var currentUserID: String? = nil
@State var displayText: String? = nil
.... is a bit redundant, I suppose?

lowlydeveloper
visit shbcf.ru