@property 的属性class

@property(class, nonatomic, assign) BOOL isFlag;

属性中描述中有个class 。这个class 是干嘛的呢?

作用

增加一个属性。(其实就是给类增加了一个setting 和getter方法,+方法,注意没有生成实例变量)

测试代码

#import 

@interface ClassProperty : NSObject
@property (class, nonatomic, assign, readonly) NSInteger userCount;
@property (class, nonatomic, copy) NSUUID *identifier;
+ (void)resetIdentifier;
@end
#import "ClassProperty.h"
static NSUUID *_identifier = nil;
static NSInteger _userCount = 0;
@implementation ClassProperty
- (instancetype)init
{
    self = [super init];
    if (self) {
        _userCount += 1;
    }
    return self;
}

+ (NSInteger)userCount {
    return _userCount;
}
+ (NSUUID *)identifier {
    if (_identifier == nil) {
        _identifier = [[NSUUID alloc] init];
    }
    return _identifier;
}

+ (void)setIdentifier:(NSUUID *)newIdentifier {
    if (newIdentifier != _identifier) {
        _identifier = [newIdentifier copy];
    }
}
+ (void)resetIdentifier {
    _identifier = [[NSUUID alloc] init];
}
@end

 ClassProperty * obj = [ClassProperty new];
    NSLog(@"%d",ClassProperty.userCount);
    NSLog(@"%@",ClassProperty.identifier);

测试结果

2018-08-27 14:25:14.274852+0800 OriginCodeAnalytical[96276:4482776] 1
2018-08-27 14:25:14.275168+0800 OriginCodeAnalytical[96276:4482776] 544F9332-6CFC-43F6-93D6-ECB90A5D22AD

这个属性,只是增加getting setting方法,我们需要自己添加静态变量(权当类成员变量)

你可能感兴趣的:(@property 的属性class)