Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Why do I get an error before "AT_NAME"?

I am kinda new at this.
I wanted to define a type based on an enum, which has all the directions a sprite can be facing in a game I am making. I defined the enum and typedef in the header for a display file. When I put it between the @interface and @end, I got a syntax error, but when I put it after the @end, I got an error in the .m file that I think has something to do with the #import. Where is the best place to put the typedef in my program: the .m file or the .h file, and where in the file? For now I used #define about 9 times, which is annoying.
I do not want to have to make a new header file for my program.

mac os x 10.5, Mac OS X (10.5.8)

Posted on Jun 3, 2010 10:01 AM

Reply
2 replies

Jun 8, 2010 11:39 PM in response to thatonegeek

Hi thatonegeek, and welcome to the Dev Forum!
thatonegeek wrote:
I defined the enum and typedef in the header for a display file. When I put it between the @interface and @end, I got a syntax error ...

Yes. A typedef doesn't want to be part of a class interface.
but when I put it after the @end, I got an error in the .m file that I think has something to do with the #import.

An error in a .h file will only be reported in the .m files which #import that header. Without the message text it's hard to guess what the compiler doesn't like about the typedef. One possibility is that one of the @interface declarations uses that enum type. To rule out that case, try putting the typedef above the @interface, e.g. between any #imports and the @interface directive.

Otherwise it might help to drop your typedef above main() in a minimal C program to rule out any syntax error. A period that wants to be a comma can be hard to spot until the enum is isolated. An Obj-C compile might report a different error every time we move the typedef without ever letting us know the typedef syntax itself is wrong.
Where is the best place to put the typedef in my program: the .m file or the .h file.

Typedefs belong in .h files. But as discussed above, they need to be visible wherever the type is used since AFAIK there's no standard syntax for the forward declaration of an enum type (though I think that's supported as a C extension by some compilers). If you're using Xcode, one approach would be to make the typedef visible globally by putting it in your _Prefix.pch file.

If none of the above is helpful please post the .h file in question. In that case please copy and paste directly from the source file to the forum and use +
Your code here
+ to format your post.

- Ray

Why do I get an error before "AT_NAME"?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.