Objective-C中属性修饰符copy,retain,assign,readonly,readwrite,nonatomic

来源:互联网 发布:伊藤洋华堂网络超市 编辑:程序博客网 时间:2024/05/21 18:40

Problem:

在Objective-C中,除了定义类的实例变量(instance variable)之外,还可以定义其属性。属性其实可以理解为类的一种变量,只不过声明为属性,可以使用@synthesize语法来自动合成变量的存取方法(getter and setter methods)。属性的定义类似于:

@interface ClassA

@property (nonatomic, retain) UIButton *button;

@property (nonatomic, assign) int number;

@end

其中属性前面括号里面的为属性的修饰符,有atomic、nonatominc、readonly、readwrite、copy、retain、assign等(在ARC中,retain、assign分别为strong、weak)。那么这些修饰符怎么去理解,它们又有什么区别呢?

Solution:

Discussion:

(remain summarize)

0 0
原创粉丝点击