From the course: Programming for Non-programmers: iOS 17 and Swift 5

Unlock this course with a free trial

Join today to access over 23,400 courses taught by industry experts.

Understanding variables and constants

Understanding variables and constants

"

- [Instructor] Programming is made up of multiple foundational building blocks, and the first of those are called variables, and constants, which are sort of a type of variable. Let's talk about what variables are. Variables are similar to nouns in a spoken language. So if you think of any noun, any person, place, or thing, that's what variables are. There are the things of code. They are named containers that hold data, and they're used all over in every application. So here's a basic example of a variable. This is called score, and it's set equal to the value of 10. A place where you might use a variable like this is in a game, so you have some way to keep track of the player's score. It's a value that represents a number, and then the variableness of it is that it can change over time. So to create it, we use the var keyword, then the name of the variable, and then we give it a value with the equal sign, and we set the value on the right side of the equal sign. In Swift, declaring…

Inhalt