From the course: Make SwiftUI Playgrounds Applications

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Variables and scope

Variables and scope

- [Instructor] We've been using constants and literals up to now. However, you're going to want values to change as you build apps. For that, you need variables. Let's look at variables and how to use 'em. We'll start with the same code from the last lesson. I'm going to try adding two more lines to this code, so that I can change the size and the area and how I make them. So I'm going to do size equals 10. And I'll use area, and I'll do that with pi times size. And you notice we get a bunch of errors here. Let's take a look at what those errors are. So I'll just pick on the area one here. And it says cannot assign value, area is a let constant. So it's saying that let will only let you keep one type of value. You need to tell the swift compiler you'll be changing this value. Fortunately, the difference between a constant and a variable is a simple keyword. And you can see it right there in the fix that says to…

Contents