ary*_*axt 10 global-variables objective-c extern
我正在尝试使用extern变量.
它抱怨因为使用numberWithInt我没有传递一个包含作为我变量的值
所以我删除了const并且它抱怨extern变量必须是常量,那么这里的解决方案是什么?
我不想使用INT
.h
extern NSNumber const *MoveID;
.m
NSNumber const *MoveID = [NSNumber numberWithInt:1];
Run Code Online (Sandbox Code Playgroud)
bee*_*fon 15
您可以尝试执行以下操作:
.H
extern NSNumber *MoveID;
Run Code Online (Sandbox Code Playgroud)
.M
NSNumber *MoveID;
@implementation MYGreatClass
+ (void) initialize {
static bool done = FALSE;
if(!done){ // This method will be called again if you subclass the class and don't define a initialize method for the subclass
MoveID = [[NSNumber numberWithInt:1] retain];
done = TRUE;
}
}
Run Code Online (Sandbox Code Playgroud)