代码:
main.m:
#import <Foundation/Foundation.h> #import "MyObject.h" int main(int argc, const char * argv[]) { @autoreleasepool { [MyObject setFlag:YES]; NSLog(@"%@", [MyObject flag] ? @"YES" : @"NO"); } return 0; }
MyObject.h:
#import <Foundation/Foundation.h> @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
时间: 2024-11-05 15:52:52