I have a weird crash that has begun to occur that I am unable to replicate and mostly happens on the iPad 10th generation.
The crash occurs when applying a snapshot for a UICollectionViewDiffableDataSource. The content models for the datasource are shown below and they conform to Hashable. I added a custom Hashable conformance in an attempt to fix the crash I am getting but it has not helped. Previously I just used automatic conformance.
struct FormationContent: Hashable {
let block: Block
func hash(into hasher: inout Hasher) {
hasherbine(block)
}
enum Block: Hashable {
case formation(FormationCellViewModel)
case add(isSelected: Bool)
func hash(into hasher: inout Hasher) {
switch self {
case .formation(let viewModel):
hasherbine("formation")
hasherbine(viewModel.id)
case .add(let isSelected):
hasherbine("add")
hasherbine(isSelected)
}
}
}
struct FormationCellViewModel: Hashable {
let id: UUID
let title: String
let isSelected: Bool
}
}
Below are the crash logs that don't appear to show any duplication. Oddly the add section does not appear but I guess the crash is occurring before the datasource attempts to display that in the next section:
Fatal: supplied item identifiers are not unique.
Duplicate identifiers:
{( footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 65BF74DC-FC44-4E2E-8984-DD036543B0AD, title: "5-3-2", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 2397B8DE-DD7C-4CED-B78D-5BDB30F0CB15, title: "4-5-1", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: F0CBB71C-B39B-4674-B950-F4CFF0FF8E72, title: "4-4-2", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 71609229-BCC8-457F-977F-618335BC9E0B, title: "4-3-3", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 5FA5DBE3-87A2-4CE4-9D19-2588CFE5DC28, title: "4-3-2-1", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 631FD123-F4D9-43A2-BFA1-64F6A739B9C3, title: "3-5-2", isSelected: false))) )}
The FormationContent model is for two sections that are handled with the different blocks. The formation id comes from a CoreData model and is unique.
This is how I apply my snapshot:
private func applyFormationSnapshot(_ formationsContent: [FormationLayout.Section : [FormationContent]]) {
var snapshot = NSDiffableDataSourceSnapshot<FormationLayout.Section, FormationContent>()
snapshot.appendSections([.main, .add])
if let formations = formationsContent[.main] {
snapshot.appendItems(formations, toSection: .main)
}
if let addFormation = formationsContent[.add] {
snapshot.appendItems(addFormation, toSection: .add)
}
formationsDataSource.apply(snapshot, animatingDifferences: true)
}
Is there anything obvious that I am doing wrong? I plan to add some logging of the formation content models to help get a better understanding of the issue via Firebase.
Thanks
I have a weird crash that has begun to occur that I am unable to replicate and mostly happens on the iPad 10th generation.
The crash occurs when applying a snapshot for a UICollectionViewDiffableDataSource. The content models for the datasource are shown below and they conform to Hashable. I added a custom Hashable conformance in an attempt to fix the crash I am getting but it has not helped. Previously I just used automatic conformance.
struct FormationContent: Hashable {
let block: Block
func hash(into hasher: inout Hasher) {
hasherbine(block)
}
enum Block: Hashable {
case formation(FormationCellViewModel)
case add(isSelected: Bool)
func hash(into hasher: inout Hasher) {
switch self {
case .formation(let viewModel):
hasherbine("formation")
hasherbine(viewModel.id)
case .add(let isSelected):
hasherbine("add")
hasherbine(isSelected)
}
}
}
struct FormationCellViewModel: Hashable {
let id: UUID
let title: String
let isSelected: Bool
}
}
Below are the crash logs that don't appear to show any duplication. Oddly the add section does not appear but I guess the crash is occurring before the datasource attempts to display that in the next section:
Fatal: supplied item identifiers are not unique.
Duplicate identifiers:
{( footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 65BF74DC-FC44-4E2E-8984-DD036543B0AD, title: "5-3-2", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 2397B8DE-DD7C-4CED-B78D-5BDB30F0CB15, title: "4-5-1", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: F0CBB71C-B39B-4674-B950-F4CFF0FF8E72, title: "4-4-2", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 71609229-BCC8-457F-977F-618335BC9E0B, title: "4-3-3", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 5FA5DBE3-87A2-4CE4-9D19-2588CFE5DC28, title: "4-3-2-1", isSelected: false))),
footballformation.FormationContent(block: footballformation.FormationContent.Block.formation(footballformation.FormationContent.FormationCellViewModel(id: 631FD123-F4D9-43A2-BFA1-64F6A739B9C3, title: "3-5-2", isSelected: false))) )}
The FormationContent model is for two sections that are handled with the different blocks. The formation id comes from a CoreData model and is unique.
This is how I apply my snapshot:
private func applyFormationSnapshot(_ formationsContent: [FormationLayout.Section : [FormationContent]]) {
var snapshot = NSDiffableDataSourceSnapshot<FormationLayout.Section, FormationContent>()
snapshot.appendSections([.main, .add])
if let formations = formationsContent[.main] {
snapshot.appendItems(formations, toSection: .main)
}
if let addFormation = formationsContent[.add] {
snapshot.appendItems(addFormation, toSection: .add)
}
formationsDataSource.apply(snapshot, animatingDifferences: true)
}
Is there anything obvious that I am doing wrong? I plan to add some logging of the formation content models to help get a better understanding of the issue via Firebase.
Thanks
Share Improve this question asked 2 days ago EdwardEdward 2,9742 gold badges30 silver badges40 bronze badges1 Answer
Reset to default 0Try making everything Identifiable
instead of Hashable
, such as:
struct FormationContent: Identifiable {
let id = UUID() // <--- here
let block: Block
enum Block: Identifiable {
case formation(FormationCellViewModel)
case add(isSelected: Bool)
var id: UUID { // <--- here
switch self {
case .formation(let viewModel): return viewModel.id
case .add(let isSelected): return UUID()
}
}
}
struct FormationCellViewModel: Identifiable {
let id = UUID() // <--- here
let title: String
let isSelected: Bool
}
}