开发者

Objective-C error: expected '=', ',', ';', 'asm' or '__attribute__' before 'class'

I'm getting this from an iPhone app I'm working on. Not sure how to interpret the error... It开发者_运维问答's thrown at a few place in my code. I can't see any pattern of occurrence.

Is this a generic error? What's the meaning of it?


The error you posted indicates that you have a syntax error around your use of class. Manually inspect the first location the error is reported, and you might notice the cause.

To help you debug further, please include the surrounding code so we can better help you.

Most common causes:

  1. Missed @ in @class for forward class declaration in headers
  2. Missed ; after the declaration of an enum, a structure, or a typedef
  3. Copied C++ code, where class is used to declare a structure, but code is invalid in Objective-C


I've just solved this exact same problem and I have been tearing my hair out over it.

GCC wasn't highlighting the problem in the header file where the error actually occurred - I had a stray 'B' character at the bottom of a header file (from running command-B to compile). The error was then being thrown in the .m file and other .h files which included the problematic one, often at the @class statement.

If it's throwing an issue with your @class statement, the problem is almost definitely in one of the preceding header files, as you include them directly beforehand - try commenting these out one-by-one and recompiling to find out which. Once you find the culprit file, finding the actual error will be much easier.


Same as Ronan except this time I had a stray character in a source file just before I started importing headers (similarly it was an 's' for Command-S). This particularly threw me since the error message was associated with a library header file that I had never touched and the app was working fine for weeks before that. So if you are getting these errors associated with header files that appear to be fine and that you haven't touched look around for something like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜