@property中的 strong retain copy weak 和assign
来源:互联网 发布:观看网络直播人群分析 编辑:程序博客网 时间:2024/04/28 08:04
ratain copy assign 的本质在MRC中set方法可以模拟:
//浅copy 只复制了变量指针 @property(NSString *)name- (void)setName:(NSString *)name{ if (name!=_name) { [_name release]; _name=[name copy]; }}//深copy 复制了对象指向的内存 @property(NSMutableString *)name2- (void)setName2:(NSMutableString *)name2{ if(_name2!=name2){ [_name2 release]; _name2=[name2 mutableCopy]; }}//assign 直接复制 @property(int)age- (void)setAge:(int)age{ _age=age;}- (int)age{ return _age;}//retain 和浅copy一样只复制了指针// @property(Dog*)dog- (void)setDog:(Dog *)dog{ if (_dog!=dog) { [_dog release]; _dog=dog; [_dog retain]; }}
strong 和 retain 相似 在引入ARC之后引入strong
weak 和 assign 相似 区别:
1.weak 和 assign差不多 assign直接赋值 不参与内存管理,weak 不对内存拥有所有权,内存被清空 他也会被清空,
2.weak不可以用于非oc对象,assign可以用于非oc对象
一般用 assign 用于 int nsInteger float 等数值型变量,strong用于自定义的类的对象,除NSString其他的系统对象,copy一般用于NSString对象类型,weak 可以用于代理模式中放置对象的重复引用,自定义IBOutlet控件 等
0 0
- @property中的 strong retain copy weak 和assign
- property中的strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- property中的strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- property中的strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- property中的strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- property中的strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- weak assign 和strong copy retain异同
- strong/weak/assign/copy/retain
- @property详解:nonatomic,retain,copy,assign,weak,strong
- property 描述 之copy assign retain strong weak
- iOS @property中retain,copy, assign,strong,weak详解
- property的修饰 retain、strong、weak、assign、copy的概念
- iOS中 property中的属性strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- property参数strong 、weak、copy 、assign 、retain 、unsafe_unretained 与autoreleasing区别和作用详解
- Objective-c 的 内存管理和@property strong,weak,assign,copy,retain等关键字介绍
- OC中的关键字,weak,assign,copy,strong,nonatomic,retain
- retain、copy、assign、 strong、weak、autorelease的用法和区别
- strong,weak,copy,retain和assign的区别
- leetcode系列(40)Merge K Sorted Lists
- OC内存管理初级
- birt中根据两个表的差别生成一个饼图
- HDU2098
- 关于Unkown entity的解决方法
- @property中的 strong retain copy weak 和assign
- Otsu算法 灰度图像二值化
- iOS中 CGGeometry 类方法总结
- Objective-C的基本类方法,举例
- c++中介者模式
- thinkphp——关于前台模板显示顶级栏目及二级栏目及对应的商品信息
- Android【百度地图】模式切换(2)
- PHP处理大文件下载
- 黑马程序员--集合(上)