From the course: Building Your First iOS 17 App
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Handling invalid values
From the course: Building Your First iOS 17 App
Handling invalid values
- [Instructor] So the way our application works is we show the tip amount if we can convert this amount to a number, but if we can't convert it to a number, we instead show nothing, which causes the user interface to shift. What if we had a way to show information to the user about what's wrong and why it's not working? Let's take a look at how to handle that using something called an else statement. In the same way that an if statement runs if a condition is true or successful, an else statement can run if a statement is evaluated as false or if it is unsuccessful, in our case, of converting a string to a double value. To do that, go after the closed curly brace on line 35. After the if statement, type a space and type the word else, and then an open curly brace and a return to have Xcode write the close curly brace for you. And on line 36, I'm going to create a text view with a message inside of it. This message is…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.