1

我有如下代码:

@interface InterfaceWithACategory () {
    ... Some variables
}
@end

在 XCode 4.0.2 中编译时效果很好

现在我对 XCode 4.2 + iOS SDK 5.0 进行了升级(已经为这个愚蠢的想法责备自己)并且出现错误“预期标识符或 '(' 在 '{' 标记之前”。

任何帮助将非常感激。

4

2 回答 2

1

通常您不能在类扩展上创建 iVar,但是您可以使用 @property 语法设置声明的属性。

@interface InterfaceWithACategory ()
@property (retain) NSArray *inDisArray;
@property (retain) NSInteger iThinkYouGetInt;
@end

但是在 ObjC 2.1 中你可以这样做,但是将你的编译器设置为Apple LLVM 3.0我在 Xcode 4.2 + iOS5.0 上测试了它并且它可以工作。

于 2011-10-20T12:18:29.537 回答
0

类别不允许您添加实例变量

于 2011-10-20T12:16:47.487 回答