I have a crash error message - Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: itemIdentifier'
I used a UITableViewDiffableDataSource to implement my UITableView. And when I try to "dataSource?.apply" a have a crash. It happens only on iPad, iPhone works fine
Do you know what is a reason and How to solve it?
Code example
class myVC: UIViewController {
struct Section: Hashable {
enum Kind: Hashable, CaseIterable {
case `default`
case full
}
let title: String? = nil
let kind: Kind
let items: [Item]
}
struct Item: Hashable {
let title: String?
let detailTitle: String?
let subDetailTitle: String?
let image: UIImage?
let isActionable: Bool
let action: ((Any?) -> Void)?
}
private typealias DataSource = UITableViewDiffableDataSource<Section, Item>
private typealias Snapshot = NSDiffableDataSourceSnapshot<Section, Item>
private var dataSource: DataSource?
private var flag: Bool = false
func setData(sections: [TimeLogDetailViewController.Section]) {
var snapshot = Snapshot()
sections.forEach { section in
snapshot.appendSections([section])
snapshot.appendItems(section.items, toSection: section)
}
dataSource?.apply(snapshot, animatingDifferences: false)
}
func configureSections() -> [TimeLogDetailViewController.Section] {
var sections = [TimeLogDetailViewController.Section]()
if !flag {
sections.append(configFirstSection())
} else {
sections.append(emptySection(kind: .default))
sections.append(configSecondSection())
}
return sections
}
func emptySection(kind: TimeLogDetailViewController.Section.Kind) -> TimeLogDetailViewController.Section {
Section(kind: kind, items: [])
}
func configFirstSection() -> [Item] {
[Item(title: "Title"))]
}
func configHeaderSectionItems() -> [Item] {
return configFirstSection().append([Item(title: "SecondTitle")])
}
}