开发者

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

开发者 https://www.devze.com 2023-01-23 02:18 出处:网络
I wonder if it is possible to write s开发者_如何学编程omething like this in the .m file: @interface MyController () {//ERROR here

I wonder if it is possible to write s开发者_如何学编程omething 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消