objcio / core-data

Sample code for the objc.io Core Data book

Home Page:https://www.objc.io/books/core-data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update fails if the cell is not visible

Sydney-o9 opened this issue · comments

If the UICollectionViewCell being updated is not visible, the update will trigger wrong cell type:

case .update(let indexPath, let object):
    guard let cell = self.collectionView.cellForItem(at: indexPath) as? Cell else { fatalError("wrong cell type") }
    self.delegate.configure(cell, for: object)

https://github.com/objcio/core-data/blob/master/Moody/Moody/CollectionViewDataSource.swift#L69-L70

I'm sure there must be a reason, but why not use this instead:

case .update(let indexPath, let object):
    self.collectionView.reloadItems(at: [indexPath])