static int nextId;
@interface Man : NSObject
@property (nonatomic) int manId;
@end
@implementation Man
//type initializer: runs once before
//the first use of the class
+ (void)initialize {
if (self == [Man class]) {
nextId = 0; //getLastDbId()
}
}
- (instancetype)init {
self = [super init];
if (self) {
nextId++;
_manId = nextId;
}
return self;
}
@end
Man *man = [Man new];
//man.manId is 1