I wanted update my table view with new data. My table view could work with 2 different cells: TitleTableViewCell and AppartmentCardTableViewCell. When I reload my table view I want to replace all TitleTableViewCell by some AppartmentCardTableViewCells. This is log of elements that were before updated and that I expected to see after update:
[ArraySection(
model: TestApp.DiffableListSection<TestApp.ListSection>,
elements: [TestApp.TableItemViewModel(differenceIdentifier: "tag-title-Yandex", data: TestApp.TitleDataModel(tag: Optional(TestApp.AddressEntity(dto: TestApp.AddressDTO(addressId: -1, addressName: "Yandex", longitude: 37.588144, latitude: 55.733842))), title: "Yandex"), reuseIdentifier: "TitleTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: Optional((Function)), style: Optional((Function))), TestApp.TableItemViewModel(differenceIdentifier: "tag-title-Yevropeysky", data: TestApp.TitleDataModel(tag: Optional(TestApp.AddressEntity(dto: TestApp.AddressDTO(addressId: -1, addressName: "Yevropeysky", longitude: 37.566278, latitude: 55.744796))), title: "Yevropeysky"), reuseIdentifier: "TitleTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: Optional((Function)), style: Optional((Function)))]
)]
[ArraySection(
model: TestApp.DiffableListSection<TestApp.ListSection>,
elements: [TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil), TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil), TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil), TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil)]
)]
[
Changeset(
data: [
ArraySection(
model: TestApp.DiffableListSection<TestApp.ListSection>,
elements: []
)
],
elementDeleted: [
[element: 0, section: 0],
[element: 1, section: 0],
[element: 2, section: 0],
[element: 3, section: 0],
[element: 4, section: 0],
[element: 5, section: 0],
[element: 6, section: 0],
[element: 7, section: 0],
[element: 8, section: 0],
[element: 9, section: 0]
]
),
Changeset(
data: [
ArraySection(
model: TestApp.DiffableListSection<TestApp.ListSection>,
elements: [TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil), TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil), TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil), TestApp.TableItemViewModel(differenceIdentifier: "tag-47A539B5-3C8D-4687-BC45-32770BA5AD99", data: TestApp.EmptyDataViewModel(tag: Optional("47A539B5-3C8D-4687-BC45-32770BA5AD99")), reuseIdentifier: "AppartmentCardTableViewCell", heightStyle: TestApp.ListItemHeightStyle.automatic, map: nil, style: nil)]
)
],
elementInserted: [
[element: 0, section: 0],
[element: 1, section: 0],
[element: 2, section: 0],
[element: 3, section: 0]
]
)
]
And after that I got a crash.
2020-05-05 13:24:03.452034+0200 TestApp[86075:4912222] *** Assertion failure in -[TestApp.TableView _Bug_Detected_In_Client_Of_UITableView_Invalid_Number_Of_Rows_In_Section:], /Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3920.26.113/UITableView.m:2444
2020-05-05 13:24:03.457331+0200 TestApp[86075:4912222] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (10) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 10 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e39f0e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50ad79b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e39c88 +[NSException raise:format:arguments:] + 88
3 Foundation 0x00007fff258a3cd2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff48da4a5d -[UITableView _Bug_Detected_In_Client_Of_UITableView_Invalid_Number_Of_Rows_In_Section:] + 193
5 UIKitCore 0x00007fff48da4462 -[UITableView _endCellAnimationsWithContext:] + 17036
6 UIKitCore 0x00007fff48dbde6d -[UITableView endUpdatesWithContext:] + 112
7 UIKitCore 0x00007fff48dbe019 -[UITableView _performBatchUpdates:withContext:completion:] + 253
8 UIKitCore 0x00007fff48dbe12f -[UITableView performBatchUpdates:completion:] + 97
9 DifferenceKit 0x00000001095f250c $sSo11UITableViewC13DifferenceKitE20_performBatchUpdates33_F8DD3376103BA2712B08CDB09297309BLLyyyyXEF + 348
10 DifferenceKit 0x00000001095f0bcf $sSo11UITableViewC13DifferenceKitE6reload5using23deleteSectionsAnimation06inserthI00ehI00g4RowsI00jkI00ekI09interrupt7setDatayAC15StagedChangesetVyxG_So0ab3RowI0VyXKARyXKARyXKARyXKARyXKARyXKSbAC0P0VyxGcSgyxXEtSlRzlF + 3151
11 DifferenceKit 0x00000001095efdea $sSo11UITableViewC13DifferenceKitE6reload5using4with9interrupt7setDatayAC15StagedChangesetVyxG_So0aB12RowAnimationVyXKSbAC0L0VyxGcSgyxXEtSlRzlF + 298
12 TestApp 0x0000000107d8c515 $s8TestApp11ListUpdaterC15updateTableView_4with11newSections0E9AnimationySo07UITableG0C_AA0fG18DataSourceAnimatedCyxGSayxGAA0c6UpdateK0OtAA0C7SectionCRbzlFZyycfU_ + 3333
13 TestApp 0x0000000107ba4990 $sIeg_IeyB_TR + 48
14 libdispatch.dylib 0x000000010b3f6f11 _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x000000010b3f7e8e _dispatch_client_callout + 8
16 libdispatch.dylib 0x000000010b405d97 _dispatch_main_queue_callback_4CF + 1149
17 CoreFoundation 0x00007fff23d9da89 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
18 CoreFoundation 0x00007fff23d985d9 __CFRunLoopRun + 2041
19 CoreFoundation 0x00007fff23d97ac4 CFRunLoopRunSpecific + 404
20 GraphicsServices 0x00007fff38b2fc1a GSEventRunModal + 139
21 UIKitCore 0x00007fff48bc7f80 UIApplicationMain + 1605
22 TestApp 0x0000000107d806db main + 75
23 libdyld.dylib 0x00007fff519521fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException