简体   繁体   中英

What's wrong with putting an ivar in a class extension?

According to Apple's documentation here , this should work in my code:

@interface Menu () {
    int testIvar;

}
 -(void)privateMethod;

@end

This works if I don't try to declare an iVar. As soon as I add the curly braces and what is between them, I get this nice red warning:

Expected identifier or '(' before '{' token

What's going on here?

(Turning my comment into an answer...)

GCC of any kind won't do this for you, nor will LLVM < 2.0, as the docs you linked to state:

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

Make sure you're using the most recent compiler available to you (if you're using Xcode < 4 you may be out of luck).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM