Property Basics

suggest change

Properties can be added to a class or struct (technically enums too, see “Computed Properties” example). These add values that associate with instances of classes/structs:

class Dog {
    var name = ""
}

In the above case, instances of Dog have a property named name of type String. The property can be accessed and modified on instances of Dog:

let myDog = Dog()
myDog.name = "Doggy" // myDog's name is now "Doggy"

These types of properties are considered stored properties, as they store something on an object and affect its memory.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents