简体   繁体   中英

Is it possible to define ivars in Objective-C extension?

I wonder if it is possible to write something like this in the .m file:

@interface MyController () {//ERROR here
    Foo *privateFoo; 
}
@end

I did it but I get : Expected identifier or '{' before '{' token , I think I heard/watch a video (WWDC2010) saying this is possible or will be possible and currently only some architectures support it... but I not really sure and I cannot remember the video name.

I hope I can get some advice here.

Ignacio.

You can do this in the modern runtime (64-bit/iOS) with clang (“LLVM Compiler 1.5”) in Xcode 3.2.3 or 3.2.4, by adding -Xclang -fobjc-nonfragile-abi2 to the Other C Flags build setting. (Note that this is actually one option, not two.)

Another effect of this flag is to cause properties to be synthesized by default.

Albeit it doesn't state it explicitly, and the thread is pretty old, this document has an example at page 75 in which an ivar is added within an extension.

The Objective-C Programming Language

It is not possible to handle it this way. Categories define additional behaviour only, not state.

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