I have some code that calls an external library asynchronously to read EXIF keywords from image files :
Before I added this code, everything worked fine and images were displayed perfectly in a CollectionView.
But, since adding this code, as soon as this code has been called, the CPU fan starts to run, anywhere up to 1000% at times and it can block other asynchronous processes that normally load images in the background.
Anyone got any ideas?
Code Block func readKeywords() { keywordsForSelectedItems.removeAll() let group: DispatchGroup = .init() let queue: DispatchQueue = .init(label: "com.keywords") collectionView.selectionIndexPaths.forEach { indexPath in let item = self.collectionView.item(at: indexPath) as! CollectionViewItem let url = item.url! group.enter() queue.async(group: group) { do { try ExifReader.keywords(for: url) { keywords in if let keywords = keywords, keywords.count > 0 { self.keywordsForSelectedItems.append(keywords) } group.leave() } } catch { print(error.localizedDescription) } } } group.notify(queue: .main) { let firstValue: [String]? = self.keywordsForSelectedItems.first { keywords in keywords.count > 0 } if firstValue != nil { let keywords = self.keywordsForSelectedItems.reduce(Set(firstValue!)) { result, item in result.union(item) } self.tokenView.objectValue = keywords.sorted() } } }
Before I added this code, everything worked fine and images were displayed perfectly in a CollectionView.
But, since adding this code, as soon as this code has been called, the CPU fan starts to run, anywhere up to 1000% at times and it can block other asynchronous processes that normally load images in the background.
Anyone got any ideas?