From 757aa3539c55f6c56756ab2ddf138ce88850af49 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Wed, 8 Jan 2025 23:21:28 +0200 Subject: [PATCH] Fix ExpandableCollectionsCollectionViewHandler data source crash (#1049) --- .../Views/ExpandableCollectionsCollectionViewHandler.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift b/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift index ddd58a893..3ee0c05d0 100644 --- a/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift +++ b/Zotero/Scenes/Master/Collections/Views/ExpandableCollectionsCollectionViewHandler.swift @@ -10,7 +10,7 @@ import UIKit final class ExpandableCollectionsCollectionViewHandler: NSObject { private let collectionsSection: Int = 0 - private unowned let collectionView: UICollectionView + private weak var collectionView: UICollectionView? private unowned let dbStorage: DbStorage private unowned let dragDropController: DragDropController private unowned let viewModel: ViewModel @@ -66,6 +66,7 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject { // MARK: - Scrolling func selectIfNeeded(collectionId: CollectionIdentifier, tree: CollectionTree, scrollToPosition: Bool) { + guard let collectionView, let dataSource else { return } let selectedIndexPaths = collectionView.indexPathsForSelectedItems ?? [] if selectedIndexPaths.count > 1 { @@ -75,7 +76,6 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject { } } - guard let dataSource = dataSource else { return } let snapshot = dataSource.snapshot(for: collectionsSection) if !snapshot.items.contains(where: { $0.identifier == collectionId }) { @@ -101,7 +101,7 @@ final class ExpandableCollectionsCollectionViewHandler: NSObject { } func update(with tree: CollectionTree, selectedId: CollectionIdentifier, animated: Bool, completion: (() -> Void)? = nil) { - guard let dataSource = dataSource else { return } + guard let collectionView, let dataSource else { return } let newSnapshot = tree.createSnapshot(selectedId: selectedId) if dataSource.snapshot(for: collectionsSection).items.count == newSnapshot.items.count {