Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an NSMutableArray version of NSMapTable?

I want to keep a mutable array of weak references to a group of UIViews. NSMapTable is perfect for this need, except for one detail... NSMapTable wants a key for every value it holds.

Is there something like an NSMapArray? If not, do I need to generate throw-away unique keys for all the values I store? Should I use NSUUID to generate the key names?

EDIT: Please not that I'm talking about truly weak, self-zeroing references. CFArrays and NSValue solutions store references which won't nil themselves out when their referenced object gets deallocated...they'll just end up as junk pointers.

like image 983
zakdances Avatar asked Dec 07 '25 08:12

zakdances


1 Answers

You can try NSHashTable on iOS 6, which is like a NSSet, with support for weak references (and NSPointerArray looks nice too, but the doc says it does not support weak references under ARC).

Edit: Some people seem to think that contrary to what the doc says, NSPointerArray does zero weak references under ARC. The OS X 10.8 Foundation Release Notes say so, even though the class documentation says the opposite (iOS release notes don't say). After all, that's why they added the + weakObjectsPointerArray constructor, and the NSPointerFunctionsWeakMemory option in OS X 10.8 and iOS 6.0... You should try...

like image 104
Guillaume Avatar answered Dec 08 '25 21:12

Guillaume