常规属性的关键字
-
assign
、weak
、strong
、retain
、unsafe_unretained
、copy
、__autoreleasing
-
readonly
、readwrite
、 -
nonatomic
、atomic
、 -
__weak
、__block
iOS 9 新增
整体感觉为了和 Swift 类型更加统一引入了这些关键词
nonnull
、nullable
、null_resettable
、__null_unspecified
、__kindof
、class
-
nonnull
非空 -
nullable
可以为空 -
null_resettable
Get 方法不能为空 Set 可以为空 -
__null_unspecified
不确定是否为空 __kindof
@property (nonatomic, strong) __kindof NSObject * obj;
class
需要注意的是:
class
修饰的属性必须重写Get
和Set
方法
一般采用在.m
文件static
标记变量处理类属性读写
// 声明
@property (nonatomic, assign,class) int m;
// .m 文件
@implementation obj {
static int _value = 10;
+ (void)setCount:(int)m {
_value = count;
}
+ (int)m {
return _value;
}
}