废话不多说的咧!直接吃猪蹄!。有啥用呢有啥区别呢。简单的说呢就是为了支持ARC模式而生的(what's the ARC?that's right,here is the answer:代码中自动加入了retain/release,原先需要手动添加的用来处理内存管理的引用计数的代码可以自动地由编译器完成了,可以了吧!!!)。下面单独来讲下两个关键字: 1.strong(与retain作用类似,可以说是用来代替retain),下面代码说明一下: [size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
| [size=1em][size=1em]@property (nonatomic, strong) NSString *tempStr1;
[size=1em]@property (nonatomic, strong) NSString *tempStr2;
|
然后声明一下: [size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
| [size=1em][size=1em]@synthesize tempStr1;
[size=1em]@synthesize tempStr2;
|
然后赋值调用: [size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
[size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
| [size=1em][size=1em]self.tempStr1 = @"hello World";
[size=1em]self.tempStr2 = self.tempStr1;
[size=1em]self.tempStr1 = nil;
[size=1em]NSLog(@"tempStr2 = %@", self.tempStr2);
|
运行结果: [size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
| [size=1em][size=1em]tempStr2 = hello World
|
2.weak(观察下与strong的区别):[size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
| [size=1em][size=1em]@property (nonatomic, strong) NSString *tempStr1;
[size=1em]@property (nonatomic, weak) NSString *tempStr2;
|
然后声明一下: [size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
| [size=1em][size=1em]@synthesize tempStr1;
[size=1em]@synthesize tempStr2;
|
然后赋值调用:[size=1em][backcolor=rgb(108, 226, 108) !important][color=white !important][size=1em]?
[size=1em]1
[size=1em]2
[size=1em]3
[size=1em]4
| [size=1em][size=1em]self.tempStr1 = [[NSString alloc] initWithUTF8String:"hello World"];
[size=1em]self.tempStr2 = self.tempStr1;
[size=1em]self.tempStr1 = nil;
[size=1em]NSLog(@"tempStr2 = %@", self.tempStr2);
|
好了暂时先那么多! |