OC中的静态成员变量

代码:

main.m:

#import 
#import "MyObject.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        [MyObject setFlag:YES];
        NSLog(@"%@", [MyObject flag] ? @"YES" : @"NO");
    }
    return 0;
}

MyObject.h:

#import 

@interface MyObject : NSObject

+ (BOOL)flag;
+ (void)setFlag:(BOOL)flag;

@end

MyObject.m:

#import "MyObject.h"

static BOOL _flag;

@implementation MyObject

+ (BOOL)flag {
    return _flag;
}

+ (void)setFlag:(BOOL)flag {
    _flag = flag;
}

@end

 输出:

YES

 

转载于:https://www.cnblogs.com/xwoder/p/5827311.html

你可能感兴趣的:(OC中的静态成员变量)