gpt4 book ai didi

objective-c - 将 ivar 放在类扩展中有什么问题?

转载 作者:搜寻专家 更新时间:2023-10-30 19:42:08 24 4
gpt4 key购买 nike

根据 Apple 文档 here ,这应该适用于我的代码:

@interface Menu () {
int testIvar;

}
-(void)privateMethod;

@end

如果我不尝试声明 iVar,这会起作用。一旦我添加了花括号以及它们之间的内容,我就会收到这个漂亮的红色警告:

Expected identifier or '(' before '{' token

这是怎么回事?

最佳答案

(把我的评论变成答案...)

任何类型的 GCC 都不会为您执行此操作,LLVM < 2.0 也不会,正如您链接到的文档所述:

Using the Clang/LLVM 2.0 compiler, you can also declare properties and instance variables in a class extension.

确保您使用的是可用的最新编译器(如果您使用的是 Xcode < 4,您可能就不走运了)。

关于objective-c - 将 ivar 放在类扩展中有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9511272/

24 4 0