Перейти к содержимому

Swift Dictionaries and Unexpected Class Key Behavior

Drew and Dan in The Morning

0:00 / 0:00

Swift Dictionaries and Unexpected Class Key Behavior

1 просмотр · 1 день назад
Drew and Dan in The Morning
29 подписчиков
1 просмотр · 1 день назад
FULL EPISODE:    • Dan's glasses (and other things)   "Dan's glasses (and other things)" Apple Podcasts: https://podcasts.apple.com/us/podcast... Did you know that using a Swift class instance as a dictionary key might not behave the way you think? Turns out, even an AI caught this bug before the developer did — and the explanation is genuinely surprising. Regular Swift classes hash their property values for dictionary key comparison — not object identity. So if any property changes, the dictionary no longer recognizes the key. The fix? A type called `ObjectIdentity`, which pegs the key to the actual object in memory rather than its contents. It works, but it comes with some awkward trade-offs around type safety. This clip is pulled from the full episode linked above, where we also dig into subscription fatigue, smart glasses, Apple's new hardware leasing program, and tips for building a great app press kit. Worth the full listen.