IOS -- reasonably define the reference type of the object strong/weak/assign/copy, ios -- assign
In ios, the reference type of the object must be reasonably used:
Best Practice: in ios, any object has only one strong reference
When weak is used:
1. weak must be used for lazy loading:
For example, @ property (nonatmic, weak) IBOutlet UILabel * lbl;
Note: the so-called lazy loading means that the control is dragged to the root view through IB, and then connected to the attributes in ViewController. This method is equivalent to self. view executing the addSubview () method, that is, self. view strongly references the control, so you only need to make a weak reference in viewController.
Use of strong:
1. Non-lazy loading (alloc + init through code)
Eg. Did not drag the control to IB, declare the control in the H file, and initialize the control object in the m file. In this case, you must use strong references when declaring them. That is: @ property (nonatmic, strong) IBOutlet UILabel * lbl; the corresponding application has its initialization method: lbl = [[UILabel alloc] init];
When using assign:
1. Definitions of int, double, float, BOOL, and other numeric objects.
Eg. @ property (nonatomic, assign) BOOL tf;
Use of copy:
1. Definitions of NSString objects:
Eg. @ property (nonatomic, copy) NSString * strName;
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.