Swift iOS Development
Dictionary(uniqueKeysWithValues:) Is a Promise. One Duplicate ID From Your Backend and Your App Crashes.
Swift's Dictionary(uniqueKeysWithValues:) traps on a duplicate key, in release builds too. Here's how one repeated ID from an API crashes your iOS app, the uniquingKeysWith and grouping fixes, Unicode keys that collide, and SwiftUI ForEach's duplicate-ID cousin.
9 min read
Swift Collections
enumerated() Gives You an Offset, Not an Index. On a Slice Those Are Different Numbers.
for (i, item) in collection.enumerated() reads like it hands you an index, and on a plain Array it happens to. Feed it an ArraySlice and the same loop crashes with Index out of range. Here's the distinction Swift is actually drawing, and the two fixes.
5 min read