首页 > 代码库 > self.nsme 和 _name 的问题

self.nsme 和 _name 的问题

.h文件@interface myclass:NSObject@property(nonatomic,retain)NSArray*MyArray;@end

.m文件@implementation myclass-(void)viewDidLoad{ [superviewDidLoad]; _MyArray=[[NSArrayalloc]initWithObjects:@"1",nil]; NSLog(@"%lu",(unsignedlong)[self.MyArray retainCount]);//输出1 self.MyArray=[[NSArrayalloc]initWithObjects:@"1",nil]; NSLog(@"%lu",(unsignedlong)[self.MyArray retainCount]);//输出2 我的理解是 self.MyArray=[[NSArrayalloc]initWithObjects:@"1",nil]; 相当于 NSArray*a=[[NSArrayalloc]initWithObjects:@"1",nil]; self. MyArray =a; 而self.MyArray会调用myArray的set方法, -(void)setMyArray:( NSArray *)Array { if(Array!= MyArray) { [MyArray release]; MyArray =[Array retain]; } }}

 

self.nsme 和 _name 的问题