December 2018
Intermediate to advanced
414 pages
10h 19m
English
First, we need to distinguish value types from reference types. Value types aren't reference counted, as they are values. Think of a simple integer; the value in an integer isn't shared across all of its assignments, but copied whenever it's assigned to a new variable:
struct Box { var intValue: Int}let box = Box(intValue: 0)var otherBox = boxotherBox.intValue = 10assert(box.intValue == 0) // box and otherBox don't share the same referenceassert(otherBox.intValue == 10)
When you're passing a struct around, the value is behaving like it's copied. This is the same behavior seen when capturing values inside blocks.
Read now
Unlock full access