Swift Language Variables & Properties Property Basics

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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.



Got any Swift Language Question?