Should IBOutlets be strong or weak under ARC?
2013-11-18 15:50
387 查看
I am developing exclusively for iOS 5 using ARC. Should
to
(and subclasses) be
The following:
Would get rid of all of this:
Are there any problems doing this? The templates are using
are the automatically generated properties created when connecting directly to the header from the 'Interface Builder' editor, but why? The
has a
to its
retains its subviews.
Summarized from the developer
library:
From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong.
Outlets that you create will therefore typically be weak by default, because:
Outlets that you create to, for example, subviews of a view controller’s view or a window controller’s window, are arbitrary references between objects that do not imply ownership.
The strong outlets are frequently specified by framework classes (for example, UIViewController’s view outlet, or NSWindowController’s window outlet).
IBOutlets
to
UIViews
(and subclasses) be
strongor
weak?
The following:
@property (nonatomic, weak) IBOutlet UIButton *button;
Would get rid of all of this:
- (void)viewDidUnload { // ... self.button = nil; // ... }
Are there any problems doing this? The templates are using
strongas
are the automatically generated properties created when connecting directly to the header from the 'Interface Builder' editor, but why? The
UIViewControlleralready
has a
strongreference
to its
viewwhich
retains its subviews.
Answers
Summarized from the developerlibrary:
From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong.
Outlets that you create will therefore typically be weak by default, because:
Outlets that you create to, for example, subviews of a view controller’s view or a window controller’s window, are arbitrary references between objects that do not imply ownership.
The strong outlets are frequently specified by framework classes (for example, UIViewController’s view outlet, or NSWindowController’s window outlet).
@property (weak) IBOutlet MyView *viewContainerSubview; @property (strong) IBOutlet MyOtherClass *topLevelObject;
相关文章推荐
- Should IBOutlets be strong or weak under ARC
- Should IBOutlets be strong or weak under ARC?
- iOS5 ARC,IBOutlets 应该定义strong or weak????
- iOS5 ARC,IBOutlets 应该定义strong还是weak
- ios开发ARC,IBOutlets之strong与weak
- ios开发ARC,IBOutlets之strong与weak
- ios开发ARC,IBOutlets之strong与weak
- iOS5 ARC,IBOutlets 应该定义strong还是weak
- ios开发ARC,IBOutlets之strong与weak
- iOS5 ARC,IBOutlets 应该定义strong还是weak
- 【iOS开发系列】XIB IBOutlets use strong or weak ?
- ios开发ARC,IBOutlets之strong与weak
- 【iOS开发系列】XIB IBOutlets use strong or weak ?
- iOS5 ARC,IBOutlets 应当定义strong还是weak
- iOS5 ARC,IBOutlets 应该定义strong还是weak
- 在ARC下,IBOutlets到底应该定义成strong 还是 weak ?
- iOS5 ARC,IBOutlets 应该定义strong还是weak
- The Handler class should be static or leaks might occur.
- Error: One or more components could not be located (altera_nios2). Check Global User Libraries under Tools->Options...
- ARC学习笔记:strong、weak等详解