Be sure to use the object's reference type appropriately in iOS:
Best practice: Any object in iOS has only one strong reference
Use the weak case:
1, lazy loading method needs to use weak decoration:
such as @property (Nonatmic,weak) iboutlet UILabel *lbl;
Note: The so-called lazy loading is a charge that is dragged through IB into the root view, and then wired to correspond to the attributes in the Viewcontroller. In this way, the equivalent of Self.view executes the Addsubview () method, that is, Self.view makes a strong reference to the control, then only weak references are required in Viewcontroller.
Use the strong case:
1, non-lazy loading (need to alloc+init by code)
eg. the control was not dragged into IB, the control was declared in the H file, and the control object was initialized in the M file. This situation requires the use of strong references at the time of declaration. namely: @property (Nonatmic,strong) iboutlet UILabel *lbl; The corresponding subsequent application has its initialization method: LBL = [[UILabel alloc] init];
Use the Assign case:
1, for the int, double, float, BOOL and other numerical object definition.
[Email protected] (nonatomic,assign) BOOL TF;
When using copy:
1, for the nsstring type of object definition:
[Email protected] (nonatomic,copy) NSString *strname;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ios--a reasonable definition of the object's reference type Strong/weak/assign/copy