Skip to content
Justice Tech School

Structs

Structs are value types. Copies are independent. They get a memberwise initialiser.

Example
struct Point { var x: Int; var y: Int }
var a = Point(x: 1, y: 2)
var b = a
b.x = 99
print(a.x, b.x)

Exercise

Value type keyword.

 Point {}

Quiz Test

Are structs copied on assignment?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.