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.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With