From the course: Swift 6 Essential Training

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Variables and constants

Variables and constants - Swift Tutorial

From the course: Swift 6 Essential Training

Variables and constants

- [Instructor] All right, if you have the Chapter 2 Playground from the AdventureSwift working folder on screen, click on the variables and constants page. If not, go ahead and open that up, and let's talk about variables. So in Swift, you have two primary options for declaring variables, depending on how you plan to use them. Variables that need to be changed after they're created start with the VAR keyword, which tells the Swift compiler the value can be modified. Now to see this in action, let's complete our first objective and declare a changeable variable to store a player's health and assign it a value of 90. Start with the VAR keyword. We'll call this currentHealth. We just use the equals symbol to assign it a value. Now, Swift does encourage the use of camel case for names. So we have the first letter of our variable name lowercased, and then all following first letters are in caps. You'll also notice that we…

Contents