Reputation: 702
If I have, for example, several IBOutlets connected like this:
@property (nonatomic, strong) IBOutlet NSTextField * textField;
@property (nonatomic, strong) IBOutlet NSTextField * anotherOne;
@property (nonatomic, strong) IBOutlet NSButton * button;
/* And so on...*/
and then I am to create a parent view in IB and connect it with a parent view (also declared as strong instance variable):
@property (nonatomic, strong) IBOutlet NSView * customView;
My question is: Will ARC retain this custom view and all of its subviews if I am to do this:
NSArray * subviews = [customView subviews];
for (NSView * view in [subviews copy]) {
[view removeFromSuperview]; /* Is view being retained? */
}
I believe that setting it as a strong property causes it to be retained. Apple's documentation says that you should retain any views that you call removeFromSuperview on if you may need them later on. If the view is not being retained throughout the call to removeFromSuperview, could someone please kindly inform me on how to retain it?
Thanks.
Update: I've recently learned that calling addObject:someObj will increase the retain count on someObj. Adding it to an array will therefore cause it to be retained. Are there any leaks involved with adding it to a mutable array to increase the retain count, or will ARC handle these for me?
Upvotes: 0
Views: 78
Reputation: 2970
I wouldn't see a leak in your example. You don't need to define strong properties for objects created in IB as IB is automatically retaining them. However, when using ARC this should not make a difference as the runtime cleans up for you anyways.
I'd also hold the view elements in an array if I wanted to keep them. So an NSMutableArray would be your friend here.
Upvotes: 2