nacho4d
nacho4d

Reputation: 45138

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.

Upvotes: 2

Views: 835

Answers (3)

damix911
damix911

Reputation: 4453

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

Upvotes: 0

Jens Ayton
Jens Ayton

Reputation: 14558

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.

Upvotes: 8

jer
jer

Reputation: 20236

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

Upvotes: 0

Related Questions