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 - Swift Tutorial
From the course: Make SwiftUI Playgrounds Applications
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
-
-
First steps8m 56s
-
(Locked)
Constant and calculations7m 57s
-
(Locked)
Functions, methods, and modifiers7m 14s
-
(Locked)
HStack, VStack, and layout9m 41s
-
(Locked)
Create new files and views4m 50s
-
(Locked)
Add images10m 10s
-
(Locked)
Learn about Swift types9m 32s
-
(Locked)
Variables and scope10m 33s
-
(Locked)
Using if{}else{}8m 24s
-
(Locked)
More if{}else{}12m 46s
-
(Locked)
Create custom functions7m 58s
-
(Locked)
Structs and classes10m 55s
-
Models and views10m 37s
-
-
-