You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm experimenting with the code in a slightly different context (so there may be no bug in the example app), but I believe there's a lurking bug in the implementation of
if an update is received for an object (say via the FetchedResultsDataProvider invoking it's delegate - DataProviderDelegate.dataProviderDidUpdate(updates: [DataProviderUpdate<Object>]?)) for an object which is known and in the model, but has become off-screen, then inside the batch update's .Update(let indexPath, let object): clause, then the line
will fail because self.collectionView.cellForItemAtIndexPath(indexPath) can return nil for cells which are out of range, or simply because they're offscreen. If there's no cell, it's likely the right approach is to check for a valid cell before proceeding and retain the type check on the cell type for safety (i.e.. split out the nil check from the type check)... something like
case .Update(let indexPath, let object):
// Note: cell can be offscreen and therefore nil
if let c = self.collectionView.cellForItemAtIndexPath(indexPath) {
guard let cell = c as? Cell else { fatalError("wrong cell type") }
cell.configureForObject(object)
}
The text was updated successfully, but these errors were encountered:
@georgeharker stubbled across this post, we too had to implement a check for nil cells. Our context was utilizing lots of different custom cell types. Great catch and +1 on this change to implementation.
I'm experimenting with the code in a slightly different context (so there may be no bug in the example app), but I believe there's a lurking bug in the implementation of
if an update is received for an object (say via the
FetchedResultsDataProvider
invoking it's delegate -DataProviderDelegate.dataProviderDidUpdate(updates: [DataProviderUpdate<Object>]?)
) for an object which is known and in the model, but has become off-screen, then inside the batch update's.Update(let indexPath, let object):
clause, then the linewill fail because
self.collectionView.cellForItemAtIndexPath(indexPath)
can return nil for cells which are out of range, or simply because they're offscreen. If there's no cell, it's likely the right approach is to check for a valid cell before proceeding and retain the type check on the cell type for safety (i.e.. split out the nil check from the type check)... something likeThe text was updated successfully, but these errors were encountered: