1

Example .h file:

@interface MyClass : NSObject


typedef NS_ENUM(int, myType) {
    Something,
    SomethingElse,
    SomethingElseElse,
    YetAnotherSomethingElse
};

{ //Error On This Line: Expected Identifier or '('

    int aInstanceVariable;

}


//Some Methods go here
@end

Why am I getting that error (see the comment in the code above)? It works fine when below the class instance variable declaration, but I would like to use it as the type for one of my instance variables.

3
  • 2
    Did you try putting it above the @interface block? Commented Aug 21, 2013 at 21:51
  • @CarlVeazey No I didn't. That fixed it. Thanks. Wanna make a quick answer on my question or should I? Commented Aug 21, 2013 at 21:53
  • Was trying to find some reference on exactly what's legal after @interface but couldn't. Go ahead and self answer. Commented Aug 21, 2013 at 21:57

1 Answer 1

2

Thanks to @CarlVeazey, I discovered that the answer was simple: Move the typedef declaration to above @interface. The reason for this is that types cannot be owned by a class or an instance of a class, and therefore cannot be in the interface for a class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.