The “guard let / else” syntax in Swift

Last Updated: August 5, 2023By

If you’re a Swift developer you already know the power of “if let” for checking nil values.

Let’s take it to the next level with “guard / else” statement:

The “guard let / else” not only checks for nil, but after the check the variable remains a non-optional, so you can use it safely until you exit the current function.

 

Let’s dive into an example:

latest video

Latest Articles Via Inbox

iOS development, Swift, SwiftUI, programming and software engineering

Leave A Comment