Under what conditions does ios develop with assign, copy, retain, strong, weak, and assignretain?
1. assign:
Basic Types (simple type, atomic type): NSInteger, CGPoint, CGFloat, C data type (int, float, double, char, etc)
Assign applies to basic data types such as int, float, and struct, and does not apply to reference types.
Because the value type is put into the stack and follows the advanced post-exit principle, the system is responsible for managing the stack memory.
The reference type will be put into the heap. We need to manually manage the memory or use ARC to manage it.
2. copy:
Classes that contain mutable subclass that can be copied in depth, such as NSArray, NSSet, NSDictionary, NSData, NSCharacterSet, NSIndexSet, and NSString
But NSMutableArray cannot.
3. retain:
Other NSObject and its subclass objects
4. strong:
Custom object, usually strong
_ Btn = [[UIButtonalloc] init];
[Self. viewaddSubview: _ btn];
5. weak:
(1) Use weak for wire dragging with storyboard
(2) manually create controls
UIButton * btn = [[UIButton alloc] init];
_ Btn = btn;
[SelfaddSubview: _ btn];
Weak is applicable to delegate, block, and other reference types,
It will not cause a wild pointer problem or circular reference, which is very safe.