Fatal error: Duplicate values for key iOS Origin: On your device OSI layer 7 · Application Last updated 25 Nov 2026

Fatal error: Duplicate values for key: 'id'

Creating a dictionary with duplicate keys traps.

Exact message you may see Fatal error: Duplicate values for keyDictionary uniqueKeysWithValues duplicate key crashFatal error: Duplicate values for key: 'id'
Seen on: iOS Swift

Meaning

Dictionary(uniqueKeysWithValues:) crashes on duplicates. Use Dictionary(_:uniquingKeysWith:) or grouping:.

Common causes

  • Duplicate ids in input
  • uniqueKeysWithValues used
  • Data not cleaned

⚡ Quick fix

  1. Use Dictionary(items.map{($0.id,$0)}, uniquingKeysWith: { a, _ in a })
  2. Deduplicate first
  3. Validate server data

Detailed fix by platform

Swift

  1. let map = Dictionary(items.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })

How to diagnose

  1. Duplicates — in data?
  2. Initializer — unique?
  3. Merge — rule?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

AVAudioEngine: required condition is false: format.sampleRate == hwFormat.sampleRate — Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == hwFormat.sampleRate' (iOS)AVAudioEngine: requir…Cannot convert value of type — Swift: Cannot convert value of type 'X' to expected argument type 'Y' (iOS)Cannot convert value …Core Data: NSManagedObjectContext was accessed from the wrong queue — CoreData: error: Serious application error. Exception was caught during Core Data change processing (iOS)Core Data: NSManagedO…Could not cast value of type 'X' to 'Y' (as!) — Fatal error: Could not cast value of type '__NSDictionaryM' (0x1f) to 'NSArray' (0x1e) (iOS)Could not cast value …Crash report not symbolicated (missing dSYM) — Crashlytics: Missing dSYM — upload dSYMs to see readable stack traces (iOS)Crash report not symb…EXC_BAD_INSTRUCTION: Fatal error arithmetic overflow — Thread 1: Fatal error: Arithmetic operation '255 + 1' (on type 'UInt8') results in an overflow (iOS)EXC_BAD_INSTRUCTION: …ForEach: the ID occurs multiple times — ForEach<Array<Item>, String, Text>: the ID abc occurs multiple times within the collection, this will give undefined results! (iOS)ForEach: the ID occur…Index out of range — Swift: Fatal error: Index out of range (iOS)Index out of rangeFatal err…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.