Hashable.hash(into:) problem on iOS 9

Hi guys,

I am using custom implementation of Hashable protocol on my classes using fairly primitive logic using Hasher.combine() on several String/Int based fields.

Everything seems to be working really well on Linux, macOS, and iOS 10, 11, 12, 13, 14.

On iOS 9 with the app compiled using Xcode 11.5 however I started receiving lot of random crashes where an object used as a key in a Set or Dictionary is not there, swift crashes with Set or Dictionary containing duplicate keys, etc.

It all points toward some kind of issue where for my objects during the app run Hasher.combine() is called multiple times for the same object with different random seed, thus generating different hashValue for the same object during the same app run.

To indicate, here is the precondition on line 5 that fails:

1. let key = SomeKey()
2. let dict = [:]
3. precondition(dict[key] == nil, "")
4. dict[key] = SomeObject()
5. precondition(dict[key] != nil, "")

I'm trying to figure out whether this rings a bell for somebody since it is 100% iOS 9 specific.

thanks for any pointers,

Might as well ping over https://developer.apple.com/forums/ too, since this is iOS specific.

The code above doesn’t even compile to begin with. Are you missing something?

It's a pseudo code to show that key placed in a Dictionary is immediately not there.

I don't know your use case but there's probably no reason to support iOS 9 (for anything). iOS updates are free. There are some devices that can't go beyond iOS 9 but probably not many are still in use. Apple recommends only supporting iOS versions two back from the current newest released version, which is iOS 13 currently and will be iOS 14 in a month or so.

This is a general problem that has existed for a decade or more. It's hard to write new code that supports old iOS versions. It's difficult or impossible to buy devices that have old iOS versions on them. If you discover bugs you may find old online discussions of how to work around them. If you are the new discoverer of an old bug then you're on your own. And there won't be much online interest in helping you figure it out either.

Anyway, good luck.

1 Like