copy的使用
如果是mutable,则copy为新的obj(引用计数为1);
入股市immutable,则retain;
strong 指向某个对象,引用计数+1
assign
weak 指向某个对象,但是不+1
NSString
NSNumber
NSString/NSMutableString
NSArray/NSMutableArray
NSDictionary/NSMutableDictionary
NSSet/NSMutableSet
对变量的修饰符
__strong +1
__weak 不加1,空位nil
__unsafe_unretained 不加1,空的时候就是野指针 可以忽略
apple文档:
https://developer.apple.com/library/ios/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011226-CH1-SW11
http://www.jianshu.com/p/4a1d1921284b
相关推荐
IOS中(assign,retain,copy,weak,strong)的区别以及nonatomic的含义 我们在声明@property 属性时,总是要在括号中写上assign、retain、copy、weak、strong中的一个,很多时候,我们仅仅只是按照习惯去写经常写...
只要学过 iOS 的人,都会对 strong、weak、copy等关键字应该都会很熟悉。weak 属性关键字就是弱引用,它不会增加引用计数但却能保证指针的安全访问,在对象释放后置为 nil,从而避免错误的内存访问。主要为了解决...
@protocol ZSegmentedControlDelegate ...@property (nonatomic, weak)id <ZSegmentedControlDelegate> delegate; //@property (nonatomic, copy) void (^indexChangeBlock)(NSUInteger index);
strong retain copy assign weak unsafe_unretained 方法命名 getter = setter = <name> 结论 1、原子性 (1)atomic 原子性,可以理解成就是生成getter、setter方法时,编译器会自动为程序添加...
retain,strong, copy,weak,assign,readonly, readwrite, unsafe_unretained 下面来分别讲讲各自的作用和区别: retain,计数器加1, (增加一个指向内存的指针) 对应release(计数器-1) setter 方法对参数进行 ...
简述OC中内存管理机制。与retain配对使用的方法是dealloc还是release,为什么?需要与alloc配对使用的方法是dealloc还是...readwrite,readonly,assign,retain,copy,nonatomic 、atomic、strong、weak属性的作用
前言 我们在开发的时候会用到很多常用的代码,比如UITableView的代理,一般情况下我们要么自己敲要么复制粘贴,但是Xcode有一个功能,可以用一行代码敲出你预设的一段代码。...3.copy: @property (nonato
@property (copy, nonatomic, readonly) NSArray *items; @property (assign, nonatomic, readonly) NSInteger maximumNumberInRow; @property (assign, nonatomic, getter=isOpen) BOOL open; @property (weak, ...
主要给大家介绍了关于iOS常见的几个修饰词的相关资料,iOS修饰词包括assign、weak、strong、retain、copy、nonatomic、atomic、readonly、readwrite,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
Strong Variables 408 Weak Variables 409 @autoreleasepool Blocks 410 Method Names and Non-ARC Compiled Code 411 18 Copying Objects 413 The copy and mutableCopy Methods 413 Shallow Versus Deep Copying ...