gpt4 book ai didi

objective-c - Objective C - 如何使用外部变量?

转载 作者:太空狗 更新时间:2023-10-30 03:25:40 25 4
gpt4 key购买 nike

我正在尝试使用外部变量。

它提示说因为使用了 numberWithInt 我没有传递一个常量作为我的变量的值

所以我删除了 const 并且它提示外部变量必须是常量,那么这里的解决方案是什么?

我不想使用 INT

.h
extern NSNumber const *MoveID;

.m
NSNumber const *MoveID = [NSNumber numberWithInt:1];

最佳答案

您可以尝试执行以下操作:

.h

extern NSNumber *MoveID;

.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;
}
}

关于objective-c - Objective C - 如何使用外部变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4360327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com