diff --git a/Sources/PubNubChatComponents/ManagedEntityListViewModel.swift b/Sources/PubNubChatComponents/ManagedEntityListViewModel.swift index 88246cb..a7c6eb8 100644 --- a/Sources/PubNubChatComponents/ManagedEntityListViewModel.swift +++ b/Sources/PubNubChatComponents/ManagedEntityListViewModel.swift @@ -375,21 +375,26 @@ open class ManagedEntityListViewModel: } // MARK: - Data Source + public var dataSourceSnapshotWillAppply: ((NSDiffableDataSourceSnapshot) -> (NSDiffableDataSourceSnapshot))? - public var dataSourceSnapshotWillAppply: ((NSDiffableDataSourceSnapshot) -> (NSDiffableDataSourceSnapshot))? open func controller( _ controller: NSFetchedResultsController, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference ) { - let snapshot = snapshot as NSDiffableDataSourceSnapshot + guard let dataSource = dataSource else { + PubNub.log.error("dataSource is nil") + return + } + let snapshot = snapshot as NSDiffableDataSourceSnapshot let finalSnapshot = dataSourceSnapshotWillAppply?(snapshot) ?? snapshot - dataSnapshotQueue.async { [dataSource] in - dataSource?.apply( - finalSnapshot, - animatingDifferences: true - ) + dataSnapshotQueue.async { + dataSource.apply(finalSnapshot, animatingDifferences: true) { + if #unavailable(iOS 15) { + dataSource.apply(finalSnapshot, animatingDifferences: false) + } + } } }