Skip to content

Commit a135cf2

Browse files
committed
Fixed collection data source with leak collection view.
1 parent c9ea2e9 commit a135cf2

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

Sources/SPDiffable/DataSource/SPDiffableCollectionDataSource.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import UIKit
3131
open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SPDiffableSection, SPDiffableItem> {
3232

3333
private weak var collectionView: UICollectionView?
34-
34+
3535
// MARK: - Init
3636

3737
public init(collectionView: UICollectionView, cellProviders: [CellProvider], supplementaryViewProviders: [SupplementaryViewProvider] = []) {
3838

39+
self.collectionView = collectionView
40+
3941
super.init(collectionView: collectionView) { (collectionView, indexPath, item) -> UICollectionViewCell? in
4042
for provider in cellProviders {
4143
if let cell = provider(collectionView, indexPath, item) {
@@ -91,32 +93,25 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
9193
// In this case we shoudn't set header to section snapshot.
9294
// For this case it condition only.
9395
let headerAsFirstElement: Bool = {
94-
print("collectionView: \(collectionView)")
9596
if collectionView?.collectionViewLayout is UICollectionViewFlowLayout {
96-
print("return false")
9797
return false
9898
}
9999
if collectionView?.collectionViewLayout is UICollectionViewCompositionalLayout {
100-
print("return true")
101100
return true
102101
}
103-
print("return true 2")
104102
return true
105103
}()
106-
print("headerAsFirstElement \(headerAsFirstElement)")
107104

108105
for section in sections {
109106
var sectionSnapshot = SPDiffableSectionSnapshot()
110107

111108
if headerAsFirstElement {
112-
print("call as headerAsFirstElement")
113109
let header = section.header
114110
if let header = header {
115111
sectionSnapshot.append([header])
116112
}
117113
sectionSnapshot.append(section.items, to: header)
118114
} else {
119-
print("call as DONT headerAsFirstElement")
120115
sectionSnapshot.append(section.items)
121116
}
122117

Sources/SPDiffable/DataSource/SPDiffableTableDataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ open class SPDiffableTableDataSource: UITableViewDiffableDataSource<SPDiffableSe
4444
// MARK: - Init
4545

4646
public init(tableView: UITableView, cellProviders: [CellProvider]) {
47+
self.tableView = tableView
4748
super.init(tableView: tableView, cellProvider: { (tableView, indexPath, item) -> UITableViewCell? in
4849
for provider in cellProviders {
4950
if let cell = provider(tableView, indexPath, item) {
@@ -52,7 +53,6 @@ open class SPDiffableTableDataSource: UITableViewDiffableDataSource<SPDiffableSe
5253
}
5354
return nil
5455
})
55-
self.tableView = tableView
5656
}
5757

5858
// MARK: - Apply Content

0 commit comments

Comments
 (0)