TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.