From 20be5c85585e85fe095330cae3608b54e07671e8 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 31 Jul 2019 11:24:18 -0700 Subject: [PATCH] [AltStore] Fixes crash after deleting app from home screen If the user never opened the My Apps tab, but then deleted an AltStore app from the home screen and then returned to AltStore, the app would crash when trying to update MyAppsViewController.collectionView. --- AltStore/My Apps/MyAppsViewController.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index b954623e..db3a0a31 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -688,6 +688,13 @@ extension MyAppsViewController: NSFetchedResultsControllerDelegate { func controllerWillChangeContent(_ controller: NSFetchedResultsController) { + // Responding to NSFetchedResultsController updates before the collection view has + // been shown may throw exceptions because the collection view cannot accurately + // count the number of items before the update. However, if we manually call + // performBatchUpdates _before_ responding to updates, the collection view can get + // an accurate pre-update item count. + self.collectionView.performBatchUpdates(nil, completion: nil) + self.updatesDataSource.controllerWillChangeContent(controller) }