But this crash happened only once, and the log is from Crashlytics.
It is, alas, very hard to make quick progress on issues like this without an Apple crash report [1].
Is there any scenario that this crash should happen in a code like the one I posted?
Frame 1 of your backtrace shows that the app crashed because of some sort of assertion failure. Frame 2 shows that this came from a specialisation of
_VariantDictionaryBuffer.nativeMerge(_:uniquingKeysWith:)
. This is an implementation detail within
Dictionary.merging(_:uniquingKeysWith:)
, which is something you called in frame 4. That code is super complex, so it’s not easy to determine exactly which assertion you hit.
Note If you’d like to look at the code, you can find it here. Keep in mind that you should look at the branch for the Swift tools that you’re working with (I’ve assumed 4.2). This is especially important in this case, because
_VariantDictionaryBuffer
no longer exists in master (it’s been renamed to
Dictionary._Variant
).
Beyond that I’ve got very little:
The standard reason for
Dictionary
messing up in weird ways is broken hashing, but your dictionaries are all keyed by String
. Unless you’re doing something weird with strings (a custom NSString
subclass that’s then bridged to String
), I can’t see how you could hit that problem.Another possibility is a threading problem. Earlier you wrote:
always on main thread
Are you sure that the data structures accessed by this code (and specifically the underlying
getSubscriptions(for:)
method) are all confined to the main thread?Finally, there’s always the possibility of memory corruption, but that’s a long shot. Still, if you’ve not recently run your code under the standard memory debugging tools, it’s worth giving them a try.
If I were in your shoes I’d try disassemble the code in frame 2 to see if I could track down the parameters that are being passed to the assertion failure, which might indicate where this problem is coming from. However, I’m not sure that’s worth the effort given that you’ve only got one report of this crash.
Alternatively, you could ask about this over on Swift Forums. It’s possible that someone with deep knowledge about the internals of
Dictionary
might immediately recognise this crash.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
[1] If you’re curious what challenges are involved here, check out this post.