Daniel Lyons' Notes

Ownership in Swift

Ownership is the responsibility of some piece of code to eventually cause a value to be destroyed. An ownership system is a set of rules or conventions for managing and transferring ownership.”

Modifier Caller Callee
borrowing Remains owner of original value.

No need to copy or retain value.

Responsible for keeping it alive for the duration of the callee.
No need for a release.

No implicit copying allowed.

Explicit copying is required with a copy operator.
consuming It can either give ownership of the original value to the callee OR retain or copy the value if it requires ownership of its own value. Required to release the value.

Docs

Deep Dives

keywords

borrowing keyword

consuming keyword

inout keyword

Ownership in Swift
Interactive graph
On this page
Docs
Deep Dives
keywords
borrowing keyword
consuming keyword
inout keyword