Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

kidd0717/RetainCycleExample

Repository files navigation

RetainCycleExample

An example for Swift retain cycle

RetainCycleExample

Issue

class BankAccount {
 var owner: Owner?
 init() {
 
 }
}
class Owner {
 var account: BankAccount?
 init() {
 
 }
}
let bankAccount = BankAccount()
let owner = Owner()
bankAccount.owner = owner
owner.account = bankAccount

Fix

var owner: Owner?

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

weak var owner: Owner?

RetainCycleExample2

Issue

lazy var configureCell: (UITableViewCell)->() = { cell in
 if let tableViewCell = cell as? TableViewCell {
 tableViewCell.title?.text = self.name
 }
}

Fix

lazy var configureCell: (UITableViewCell)->() = { cell in

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

lazy var configureCell: (UITableViewCell)->() = { [unowned self] cell in

RetainCycleExample3

Issue

var delegate: TableViewCellDelegate?

Fix

var delegate: TableViewCellDelegate?

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

weak var delegate: TableViewCellDelegate?

About

An example for Swift retain cycle

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /