@@ -41,8 +41,10 @@ class MyContentView : UIView, UIContentView {
41
41
sw. centerXAnchor. constraint ( equalTo: self . centerXAnchor) . isActive = true
42
42
sw. topAnchor. constraint ( equalTo: self . topAnchor, constant: 10 ) . isActive = true
43
43
sw. bottomAnchor. constraint ( equalTo: self . bottomAnchor, constant: - 10 ) . isActive = true
44
- sw. addAction ( UIAction { [ unowned sw] action in
45
- ( configuration as? Config ) ? . isOnChanged ? ( sw. isOn, self )
44
+ sw. addAction ( UIAction { action in
45
+ if let sender = action. sender as? UISwitch {
46
+ ( configuration as? Config ) ? . isOnChanged ? ( sender. isOn, sender)
47
+ }
46
48
} , for: . valueChanged)
47
49
config ( )
48
50
}
@@ -91,7 +93,7 @@ class ViewController2: UIViewController {
91
93
var datasource : UITableViewDiffableDataSource < String , UniBool > !
92
94
override func viewDidLoad( ) {
93
95
self . tableView. register ( UITableViewCell . self, forCellReuseIdentifier: " cell " )
94
- self . datasource = UITableViewDiffableDataSource < String , UniBool > ( tableView: self . tableView) { tv, ip, isOn in
96
+ self . datasource = UITableViewDiffableDataSource < String , UniBool > ( tableView: self . tableView) { [ unowned self ] tv, ip, isOn in
95
97
let cell = tv. dequeueReusableCell ( withIdentifier: " cell " , for: ip)
96
98
var config = Config ( )
97
99
config. isOn = isOn. bool
@@ -117,4 +119,7 @@ class ViewController2: UIViewController {
117
119
snap. appendItems ( ( 1 ... 100 ) . map { _ in UniBool ( uuid: UUID ( ) , bool: false ) } )
118
120
self . datasource. apply ( snap, animatingDifferences: false )
119
121
}
122
+ deinit {
123
+ print ( " farewell2 " ) // check memory management
124
+ }
120
125
}
0 commit comments