README and documentationIGListKit version: 3.0.0I'm seeing a bizarre issue where IGListKit only finds a SectionController for one of my items when it is the only item returned by objects(for listAdapter:).
The class in question is pretty simple (code below). When I do some basic debugging it appear that there is a cached SectionController present but it doesn't get returned appropriately, which is surprising given the (apparent) simplicity of the functions involved. My only supposition is that because the LoadingItem class is a native swift class some internal assumption of the NSMapTable is violated. Though this does not appear to be born out by the demo project I ginned up which appears unaffected by this bug.
# debugging crash from IGListAdapter+UICollectionView collectionView:cellForItemAtIndexPath:
(lldb) po [self.sectionMap objectForSection:indexPath.section]
LoadingItem<BC747166-6B7C-4C48-85A8-294E883B8AF6>
(lldb) po self.sectionMap.objectToSectionControllerMap
NSMapTable {
[1] Text[id=70390 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c41164a0>
[2] Text[id=70387 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116530>
[3] Text[id=70378 msgs=2] -> <texts_from_last_night.TextSectionController: 0x1c4116a40>
[5] Text[id=70379 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c41169b0>
[6] Text[id=70376 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116b60>
[8] Text[id=70380 msgs=2] -> <texts_from_last_night.TextSectionController: 0x1c4116920>
[16] Text[id=70381 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116890>
[18] Text[id=70383 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116770>
[20] Text[id=70389 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116410>
[22] Text[id=70385 msgs=3] -> <texts_from_last_night.TextSectionController: 0x1c4116650>
[23] Text[id=70388 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4115f00>
[25] Text[id=70384 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c41166e0>
[27] Text[id=70377 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116ad0>
[29] Text[id=70382 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c4116800>
[30] LoadingItem<BC747166-6B7C-4C48-85A8-294E883B8AF6> -> <texts_from_last_night.LoadingSectionController: 0x1c00f0b80>
[31] Text[id=70386 msgs=1] -> <texts_from_last_night.TextSectionController: 0x1c41165c0>
}
(lldb) po [self.sectionMap sectionControllerForSection:indexPath.section]
nil
Class in question:
class LoadingItem {
let uuid = UUID().uuidString
var lastLoadDate = Date()
var isLoading: Bool {
return container.isLoading
}
var container: TextsVC
init(container: TextsVC) {
self.container = container
}
func load() {
container.loadMore()
}
func didLoad() {
lastLoadDate = Date()
}
}
extension LoadingItem: ListDiffable {
public func diffIdentifier() -> NSObjectProtocol {
return lastLoadDate as NSObjectProtocol
}
public func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
guard let loader = object as? LoadingItem else { return false }
return self.container == loader.container
}
}
extension LoadingItem: CustomStringConvertible {
var description: String {
return "LoadingItem<\(uuid)>"
}
}
# Please include debug logs using the following lldb command:
(lldb) po [IGListDebugger dump]
IGListAdapter 0x1c0342310:
Updater type: IGListAdapterUpdater
Data source: <texts_from_last_night.TextsVC: 0x111d27250>
Collection view delegate: (null)
Scroll view delegate: (null)
Is in update block: No
View controller: <texts_from_last_night.TextsVC: 0x111d27250>
Is prefetching enabled: No
Registered cell classes:
{(
texts_from_last_night.DateCell,
texts_from_last_night.MessageCell,
texts_from_last_night.LoadingCell
)}
IGListAdapterUpdater instance 0x1c00da010:
Moves as deletes+inserts: No
Allows background reloading: Yes
Has queued reload data: No
Queued update is animated: Yes
State: Idle
Section map details:
Object and section controller at section: 0:
Text[id=70390 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c41164a0>
Object and section controller at section: 1:
Text[id=70389 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116410>
Object and section controller at section: 2:
Text[id=70388 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4115f00>
Object and section controller at section: 3:
Text[id=70387 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116530>
Object and section controller at section: 4:
Text[id=70386 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c41165c0>
Object and section controller at section: 5:
Text[id=70385 msgs=3]
<texts_from_last_night.TextSectionController: 0x1c4116650>
Object and section controller at section: 6:
Text[id=70384 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c41166e0>
Object and section controller at section: 7:
Text[id=70383 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116770>
Object and section controller at section: 8:
Text[id=70382 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116800>
Object and section controller at section: 9:
Text[id=70381 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116890>
Object and section controller at section: 10:
Text[id=70380 msgs=2]
<texts_from_last_night.TextSectionController: 0x1c4116920>
Object and section controller at section: 11:
Text[id=70379 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c41169b0>
Object and section controller at section: 12:
Text[id=70378 msgs=2]
<texts_from_last_night.TextSectionController: 0x1c4116a40>
Object and section controller at section: 13:
Text[id=70377 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116ad0>
Object and section controller at section: 14:
Text[id=70376 msgs=1]
<texts_from_last_night.TextSectionController: 0x1c4116b60>
Object and section controller at section: 15:
LoadingItem<BC747166-6B7C-4C48-85A8-294E883B8AF6>
(null)
Collection view details:
Class: UICollectionView, instance: 0x11282d600
Data source: <IGListAdapter: 0x1c0342310>
Delegate: <IGListAdapter: 0x1c0342310>
Layout: <UICollectionViewFlowLayout: 0x111e4df80>
Frame: {{0, 0}, {375, 667}}, bounds: {{0, 2521}, {375, 667}}
Number of sections: 16
2 items in section 0
2 items in section 1
2 items in section 2
2 items in section 3
2 items in section 4
4 items in section 5
2 items in section 6
2 items in section 7
2 items in section 8
2 items in section 9
3 items in section 10
2 items in section 11
3 items in section 12
2 items in section 13
2 items in section 14
1 items in section 15
Visible cell details:
Visible cell at section 12, item 0:
<texts_from_last_night.MessageCell: 0x111e779a0; baseClass = UICollectionViewCell; frame = (0 2490; 375 192); layer = <CALayer: 0x1c423cbc0>>
Visible cell at section 12, item 1:
<texts_from_last_night.MessageCell: 0x111d865e0; baseClass = UICollectionViewCell; frame = (0 2687; 375 60); layer = <CALayer: 0x1c4425fe0>>
Visible cell at section 12, item 2:
<texts_from_last_night.DateCell: 0x111e83030; baseClass = UICollectionViewCell; frame = (0 2752; 375 54); layer = <CALayer: 0x1c0236100>>
Visible cell at section 13, item 0:
<texts_from_last_night.MessageCell: 0x111d87190; baseClass = UICollectionViewCell; frame = (0 2821; 375 82); layer = <CALayer: 0x1c0237e80>>
Visible cell at section 13, item 1:
<texts_from_last_night.DateCell: 0x111d67f80; baseClass = UICollectionViewCell; frame = (0 2908; 375 54); layer = <CALayer: 0x1c4423de0>>
Visible cell at section 14, item 0:
<texts_from_last_night.MessageCell: 0x111e7e160; baseClass = UICollectionViewCell; frame = (0 2977; 375 104); layer = <CALayer: 0x1c0235f20>>
Visible cell at section 14, item 1:
<texts_from_last_night.DateCell: 0x111d84890; baseClass = UICollectionViewCell; frame = (0 3086; 375 54); layer = <CALayer: 0x1c44211a0>>
@clayreimann I see that lastLoadDate is defined as a var. Is it being mutated anywhere? If so, that'll cause any lookups to fail. W/e you use for your diffIdentifier should never change.
@rnystrom That was exactly it. I've opened a PR to update the Getting Started guide. I spent several days trying to chase this down and I'd like to save the next person that trouble (or at least try to).
Most helpful comment
@rnystrom That was exactly it. I've opened a PR to update the Getting Started guide. I spent several days trying to chase this down and I'd like to save the next person that trouble (or at least try to).