UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Fatal Error: Duplicate keys...

Forums > Swift

Some of my users exprience from time to time crash of the app. From Firebase Crashlytics I see that error message:

Fatal error: Duplicate keys of type 'Contact' were found in a Dictionary. This usually means either that the type violates Hashable's requirements, or that members of such a dictionary were mutated after insertion.

Basically Im retrieving from API array of CallLogs which I have turned into dictionary with this following code to have nice grouped logs by date, contact

private func logsByDate() {

  let groupedByDate = Dictionary(grouping: logs, by: { $0.date.removeTimeStamp ?? .distantPast })

  let groupedByContact = groupedByDate.mapValues{ (dateArray : [CallLog]) -> Dictionary<Contact, [CallLog]> in
    return Dictionary(grouping: dateArray, by: { $0.remoteParty as! Contact })
  }

  DispatchQueue.main.async {
    self.groupedLogs = groupedByContact
  }
 }

I was not able to reproduce this error on my device. Is there a way to fix this?

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.