8 Mar 2010, 12:04pm

2 comments

Objective-C: NSArray of weak references

Need an array of weak references? e.g. for delegates. Here’s some good tips.

One convenient way is to box it in a NSValue with a non-retained object.

NSValue *value = [NSValue valueWithNonretainedObjectValue:myObj];
[array addObject:value];

and when you get the object:

value = [array objectAtIndex:x];
myObj = [value nonretainedObjectValue];

Nice one, exactly what I need.

8 Nov 2011, 8:10pm
by Danyal


Yoink. Thanks.

 
*name

*e-mail

web site

leave a comment