Strong Reference Cycles
To start, you will define the types you will be interacting with: Vault
and Asset
.
You will create one vault and multiple assets to put into the vault, and then you will observe how your code affects their lifetimes.
You are going to create a new file to model your vault.
First, in the project navigator on the left side of the Xcode screen, click the yellow CyclicalAssets folder.
This will ensure that the file appears in the correct location in your project.
Next, create a new Swift file, Vault.swift
, and define a Vault
class that conforms to the CustomStringConvertible
protocol:
Vault
class (Vault.swift
)import Foundation class Vault { let number: Int init(number: Int) { self.number = number ...
Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.