From the course: Introducing App Development for iOS 14

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using if/else statements in SwiftUI

Using if/else statements in SwiftUI

From the course: Introducing App Development for iOS 14

Start my 1-month free trial

Using if/else statements in SwiftUI

- [Instructor] As I mentioned earlier, it's generally a bad idea to use these exclamation points to force unwrap values that can possibly be empty. So to handle that we can use if statements. And the reason why I kept it in a separate movie, is because I wanted to focus on the math in the previous movie, so that we can focus on the if statements for handling optionals here. Optionals are the name that Swift gives to those values that could possibly fail or be nil, meaning no value. So to handle that, we can create a new line above our text that says if and an if else statement code allows you to execute certain code if a certain condition is true. So what we want to do is say if we can turn that total into a number, then draw the text field. So if let, we'll call this constant, we're creating total num. So let is kind of like var in that it creates a value except for let refers to a value that can't change, which is known as a…

Contents