From the course: Introducing App Development for iOS 14

Unlock the full course today

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

Calculating the tip total

Calculating the tip total

From the course: Introducing App Development for iOS 14

Start my 1-month free trial

Calculating the tip total

- [Narrator] In order to display the tip amount in the text area, we need to convert our total value that's currently a string, remember it had to be a string to go inside of the text field, to a number value. So to do that, we're going to click before total in the tip amount text line, and then type double with a capital D just before it and wrap total in parentheses. When we do that, we're given a warning. The gist of this warning, is that converting a string to a number might fail. For example, the string might have spaces or text inside of it. And if we put that inside of the string and we try to convert it to a number it's going to fail. So Swift, forces you to choose how to handle that. Do you want to force it to be a default number? Or do you want to say, I don't care if it fails, which typically is a bad option. We're going to do the bad option here and I'll show you how to do it the better way in another movie.…

Contents