五、@property的参数

格式:@property(参数1,参数2)类型 名字;

参数可有可无

如:@property int age;

  @property (nonatomic,retain) UIButton* btn;

参数主要类型分3类

读写属性:readwrit/readonly

setter处理:assign/retain/copy

原子性:atomic/nonatomic

@property(assign) in a;//这里的assign是默认类型,直接赋值setter方法,而不进行retain操作,等价于@property int a;

@property (retain) Card *card;//这里的retain代表:在set方法中,release旧值,retain新值

@property (copy) Card *card;//这里的copy代表:在set方法中,release旧值,copy新值


@property (readonly) Card *card;//readonly代表只生成get方法声明

默认是readwrite,同时生成get和set方法的声明

@proerty(atomic) int no;//atomic代表给方法进行加锁,保证线程安全

@proerty(nonatomic) int no;;//nonatomic代表不需要考虑线程安全问题,IPHONE开发大部分都不需要考虑线程安全问题,所以使用nonatomic可以提高效率

原文地址:https://www.cnblogs.com/hqr9313/p/3514684.html