1

I had code like below:

@interface InterfaceWithACategory () {
    ... Some variables
}
@end

Which worked perfect when compiled in XCode 4.0.2

Now I did an upgrade (already blame myself for this stupid idea) to XCode 4.2 + iOS SDK 5.0 and have an error "Expected identifier or '(' before '{' token".

Any help would be really appreciated.

Artem Oboturov
  • 4,344
  • 2
  • 30
  • 48
  • maybe a stupid suggestion, but have you tried without the () ? – il Malvagio Dottor Prosciutto Oct 20 '11 at 11:47
  • then it would be a redefinition of the same interface, this one is a class-extension. – Artem Oboturov Oct 20 '11 at 11:51
  • then you should put a name inside brackets like: @interface InterfaceWithACategory (CategoryName) even if it's not really used – il Malvagio Dottor Prosciutto Oct 20 '11 at 12:00
  • Categories without a name inside () are perfectly acceptabale. It sounds like your frameworks got messed up in the project file. I recommend removing all frameworks from the build phase and project, then re-adding them all, 1 by 1. If that doesnt fix it, please show the exact error message your getting. – chown Oct 20 '11 at 12:05
  • Yeah, looks like it should be valid, and I'd hope that 5 hasn't broken that. (You can, BTW, install 5 without overwriting 4, if you do it right.) – Hot Licks Oct 20 '11 at 12:12

2 Answers2

1

Normally you can't create iVars on a class extension, you can however set declared properties using the @property syntax.

@interface InterfaceWithACategory ()
@property (retain) NSArray *inDisArray;
@property (retain) NSInteger iThinkYouGetInt;
@end

However in ObjC 2.1 you can do this, but set your compiler to Apple LLVM 3.0 I tested this on Xcode 4.2 + iOS5.0 and it works.

pchap10k
  • 2,066
  • 2
  • 19
  • 30
0

Categories do not permit you to add instance variables

d.lebedev
  • 2,305
  • 19
  • 27
  • 1
    A class extension is not a category. It just looks like one, but it doesn't have anything in the parens () – pchap10k Oct 20 '11 at 12:24