I am migrating my old iPhone apps from Xcode 3 to Xcode 4. I receive this error on code which used to build in Xcode 3 -- in fact I wrote it this way on purpose to hide implementation details from other modules. However, something seems to have changed in Objective-C. This code now receives the error
Cannot declare variable inside @interface or @protocol.
Remember, this is code at the top of the .m file not the .h
@interface VisualViewController ()
BOOL doReloadPhoto;
+ (void)buildVisualEffectInfo;
@property (nonatomic, retain) HandleCheckListSetting *checkListHandler;
@end
This may have compiled before, but I don't think it was doing what you think it's doing. It sounds like you want to create a private ivar in a class extension. The syntax you have is just a top-level variable, though, equivalent to:
BOOL doReloadPhoto;
@interface VisualViewController ()
// etc.
@end
You need to put it inside curly braces for it to be an ivar:
@interface VisualViewController ()
{
BOOL doReloadPhoto;
}
(Conversely, I'm not sure that this -- ivar in extension -- was possible with Xcode 3's compiler, which is probably why you did it the way you did.) It sounds like the compiler is now (sensibly) pointing out that the code you have probably isn't doing what you expect, and forcing you to make your intention completely clear.
It has also recenty become possible to declare private ivars in the @implementation
block, using the same syntax:
@implementation VisualViewController
{
BOOL doReloadPhoto;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With