Hello,
I'm wondering if it's possible to have something similar to ActionScript 3's Dictionary
object with weak keys in Objective-C. I want to be able to 'attach' an instance of a class to other arbitrary instances.
Example;
MetaData *meta = [MetaData metaDataForObject:someObject];
meta.whatever = foo;
And later:
foo = [MetaData metaDataForObject:someObject].whatever;
[foo doStuff];
The tricky part is that after the objected referenced by someObject
is dealloc'd, I want the object referenced by meta
to be released (and dealloc'd, assuming no client code has retained it).
Possible? I took a look at +[NSValue valueWithNonretainedObject:]
but I'm not sure if this is what I want because there when I later query -[NSValue nonretainedObjectValue]
it seems like I would get a pointer to garbage (how could NSValue zero the pointer when the object was dealloc'd?).
Thanks,
benjamin