From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

String interpolation

String interpolation

- [Instructor] You've probably have used string interpolation before where you add other data types to a string. You use a backslash and in parentheses put your value type. The string I have here for example, from the exercise files, I can add the size and price of a pizza. So, all I have to do is put, "I love a," and I'll use size here, "Margherita Pizza," and I'll put over here, "for," and I'll put the price. Just like that. Now, when I go ahead and run that, you'll see on the bottom it says, "I'd Love a 10 Margherita Pizza for 14.1592," blah blah blah blah. It'd be great if I could get these numbers to format better with a formatted price and with the units on the size anytime I need them. Now, Swift 5 has added some new features that make this possible. And let's go ahead and put this in. I'm going to put it just before the let here. So, I'm going to give myself a little bit of room. And you're going to do this in an extension to the StringInterpolation of string. So…

Contents