Monday, October 29, 2018

NSMutableDictionary’s Practical Limit

Vincent Bénony:

Pro tip: if your Objective-C application deals with a huge collection of objects, avoid relying on NSMutableDictionary as the “count” method returns the number of objects… modulo 0x2000000 “allKeys” and “allValues” are also affected…

Greg Titus:

Fun fact! If you make your dictionary with 0x2000001 objects in Swift and then cast it to an NSDictionary, then it works just fine from Objective-C. Can’t be a mutable dictionary that way, though.

Update (2018-10-31): Vincent Bénony:

It depends on the private class used by Foundation. For instance, if I build the dictionary with « dictionaryWithObjects:forKeys: » it works perfectly, but as soon as I create a mutable copy, it fails.

Comments RSS · Twitter

Leave a Comment