Quantcast
Channel: NSArray of weak references (__unsafe_unretained) to objects under ARC - Stack Overflow
Viewing all articles
Browse latest Browse all 13

NSArray of weak references (__unsafe_unretained) to objects under ARC

$
0
0

I need to store weak references to objects in an NSArray, in order to prevent retain cycles. I'm not sure of the proper syntax to use. Is this the correct way?

Foo* foo1 = [[Foo alloc] init];Foo* foo2 = [[Foo alloc] init];__unsafe_unretained Foo* weakFoo1 = foo1;__unsafe_unretained Foo* weakFoo2 = foo2;NSArray* someArray = [NSArray arrayWithObjects:weakFoo1, weakFoo2, nil];

Note that I need to support iOS 4.x, thus the __unsafe_unretained instead of __weak.


EDIT (2015-02-18):

For those wanting to use true __weak pointers (not __unsafe_unretained), please check out this question instead: Collections of zeroing weak references under ARC


Viewing all articles
Browse latest Browse all 13

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>