Exposing NSDictionary
While powerful, indexed ivars come with two caveats. First of all,
class_createInstance
can’t be used under ARC, so you’ll have to compile some parts of your class with-fno-objc-arc
flag to make it shine. Secondly, the runtime doesn’t keep the indexed ivar size information anywhere. Even thoughdealloc
will clean everything up (as it callsfree
internally), you should keep the storage size somewhere, assuming you use variable number of extra bytes.[…]
We already know
__NSDictionarySizes
is some kind of array that stores different possible sizes of__NSDictionaryI
.[…]
It turns out
__NSDictionaryI
doesn’t check if thekey
passed intoobjectForKey:
isnil
(and I’d argue this is a good design decision). Callinghash
method onnil
returns0
, which causes the class to compare key at index0
withnil
. This is important: it is the stored key that executes theisEqual:
method, not the passed in key.
See also Exposing NSMutableArray.
1 Comment RSS · Twitter
[…] Previously: Exploring Swift Dictionary’s Implementation, Exposing NSDictionary. […]