Swift Structs
A struct is a value type with properties and methods and a free memberwise initialiser. Use mutating for methods that change properties. Most Swift types are structs.
Example
struct Point {
var x: Int
var y: Int
mutating func move(by d: Int) { x += d; y += d }
}
var p = Point(x: 1, y: 2)
p.move(by: 3)
print(p)Exercise
Method that changes a struct.
func move() {}Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.