UITableViewDiffableDataSource re-rendering unnecessarily on iOS 14

97 Views Asked by At

I have a swift project, with a UITableView that's populated by a UITableViewDiffableDataSource.

In my model struct, I've implemented the hash() function, roughly like this:

func hash(into hasher: inout Hasher) {
            hasher.combine(self.id)
            hasher.combine(self.mandatory)
            hasher.combine(self.isHidden)
            hasher.combine(self.readOnly)
            hasher.combine(self.type)

            // These 2 lines are obviously not part of the code, they're for debugging.
            let value = hasher.finalize()
            print("******************* hash value is \(value)")
}

When one of the values in the table changes, I call UITableViewDiffableDataSource.apply.

Worth noting at this point: the model class has a currentValue that holds the actual value, that is by design not factored into the hash function.

On an iOS 15.5 simulator, it works as expected - when the value of a cell changes, the cell is not re-rendered, and the hash values logged to the console are identical.

When running the same code on an iOS 14.3 simulator though, the logs still show identical hash values, and the == overriden function isn't called, yet the cell is re-rendered.

What am I missing here? Why is iOS 14 re-rendering the cell despite the hash values being identical?

Also, just to avoid being sidetracked - I simplified the issue for the sake of brevity, so please ignore the fact that I ignore the value in the hash function, it's by design and very deliberate, despite it at first sounding like bad practice.

0

There are 0 best solutions below