From 6cfca53dc8f40860c612b7955f4605c7ad28b185 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 10 Mar 2021 14:19:26 -0600 Subject: [PATCH] Fixes game artwork not updating immediately when changed --- .../GameCollectionViewController.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Delta/Game Selection/GameCollectionViewController.swift b/Delta/Game Selection/GameCollectionViewController.swift index 6e032c4..ef16b87 100644 --- a/Delta/Game Selection/GameCollectionViewController.swift +++ b/Delta/Game Selection/GameCollectionViewController.swift @@ -608,6 +608,14 @@ private extension GameCollectionViewController if let imageURL = imageURL { + self.dataSource.prefetchItemCache.removeObject(forKey: game) + + if let cacheManager = SDWebImageManager.shared() + { + let cacheKey = cacheManager.cacheKey(for: imageURL) + cacheManager.imageCache.removeImage(forKey: cacheKey) + } + DatabaseManager.shared.performBackgroundTask { (context) in let temporaryGame = context.object(with: game.objectID) as! Game temporaryGame.artworkURL = imageURL @@ -617,6 +625,13 @@ private extension GameCollectionViewController SyncManager.shared.recordController?.updateRecord(for: temporaryGame) DispatchQueue.main.async { + if let indexPath = self.dataSource.fetchedResultsController.indexPath(forObject: game) + { + // Manually reload item because collection view may not be in window hierarchy, + // which means it won't automatically update when we save the context. + self.collectionView.reloadItems(at: [indexPath]) + } + self.presentedViewController?.dismiss(animated: true, completion: nil) } }