Post

Replies

Boosts

Views

Activity

Reply to Why UICollectionViewDiffableDataSource compares items by reference
Which is even more weird is that it actually calls in to this block with the right data, I and the label colour is set to red, but the UI doesn't update 🤷‍♂️ could you explain please? swift dataSource = UICollectionViewDiffableDataSourceSection, Month(collectionView: collectionView) { (collectionView: UICollectionView, indexPath: IndexPath, item: Month) - UICollectionViewCell? in             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "monthcell", for: indexPath) as! MonthCollectionViewCell             cell.label.text = item.name             cell.label.textColor = item.isSelected ? .systemRed : .systemBlue             return cell }
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Why UICollectionViewDiffableDataSource compares items by reference
That's not the case here as I neither subclass NSObject nor overload the optional == operator. proof: swift class Month: Hashable { let name: String     internal init(name: String) {         self.name = name     }     static func == (lhs: Month, rhs: Month) - Bool {         print("Month overloaded")         return false     }     func hash(into hasher: inout Hasher) {         hasher.combine(name)     } } let a: AnyHashable = Month(name: "ab") let b: AnyHashable = Month(name: "ab") a == b // prints: `Month overloaded`
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21