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

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:
Missed # in #class for forward class declaration in headers
Missed ; after the declaration of an enum, a structure, or a typedef
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.

Related

iOS - expected '=', ',', ';', 'asm' or '__attribute__' before typedef [duplicate]

I'm trying to port the speakhere example into another app and I'm having issues. I copied all the files, and all the frameworks, but for some reason I get a bunch of compile errors that I've never seen before and thus don't know what to do. The only difference is that i'm not suing IB and so i had to change it slightly.
What does error: expected '=', ',', ';', 'asm' or '__attribute__' before 'foo' mean?... I get this error multiple times for different files
In my situation the first error is pointing at 'MeterTable'.. a class that includes <stdlib.h>,<stdio.h> and <math.h>. But those files seem to be importing fine (if i remove them i get more errors)
Any suggestions on how to debug this?
TIA!
EDIT:
I still can't seem to figure it out. I'm literally just copying files from the example into another project. Can someone check it out please ? SpeakHerePort.zip and the original is here SpeakHere.zip
Your problem is that you are compiling SpeakHerePortAppDelegate.m, which is an Objective C file, but it is indirectly including MeterTable.h which is a C++ header file.
Rename it to SpeakHerePortAppDelegate.mm (double m) so that it is compiled as Objective C++ and your problem is resolved.
Name all your files .mm and then all your code will be compiled as Objective C++
In my case, the .h and .m in question are built fine with regular target, and the App can run as well.
However after the subset of the files are moved under a static library target, it gets this compile error when the static library is built.
Was stuck for a while & tried the above mentioned techniques, unfortunately they didn't help in my case.
Noted that this error happened only for the NSString*, for e.g.,
extern double const kTimeout; // fine
extern NSString* const kImageType; // compile error
After the above analysis & little break, eventually the problem is resolved by adding the the following import to the .h - "Foundation/Foundation.h"
It sounds like an unfinished declaration, probably in a header file. Search for 'foo' (or whatever the symbol actually is) across all project files, using ⇧⌘F (Edit ▸ Find ▸ Find In Project...) in Xcode, and/or examine the headers you're including where MeterTable is declared. Sometimes the compiler gets confused about the actual location of the error, since header files are frequently #imported into other files, so the problem can be manifest in multiple locations.
This might not have applied to this exact situation, but I had this exact error too, which was caused by a bad forward declaration. In Objective-C, make sure your forward-declares begin with the # sign - e.g.
#class MyClass;
Those of us still on autopilot from C++ will forget the #, see that XCode has highlighted class as a reserved keyword, and think all is well with the world. It is not.
It means that you have a syntax error. If you paste the code in question, it's easier to debug.
I had a similar scenario to some of the posts above. I'd written a C++ class based off of the examples in the Audio Queue Services documentation, and had this compilation issue in a test project. This post helped a tremendous amount.
Today, I'm incorporating the C++ class in my project, and got the build error again. In my scenario, I had to also set the type (using the "Get Info" window) to sourcecode.cpp.objcpp for the objective-c class that was calling my C++ class.

iPhone app: "Parse issue - expected ';' after #synthesize"

I'm working on an iPhone app and got this strange things happening.
I have a property declared in my .h file:
BOOL shouldProcessVenueListRequest;
#property(nonatomic, assign) BOOL shouldProcessVenueListRequest;
So far, so good. Then in my implementation .m file:
#synthesize shouldProcessVenueListRequest;
This works perfectly well for about 20 other properties, but for this one, I'm getting an error in the implementation: "Parse Issue - Expected ';' after #synthesize" - and the error pointer is in the middle of the variable name - see the image.
I tried removing and re-adding this property manually; tried copy/paste variable name from .h - nothing worked. I'm totally confused about this now. Any help is greatly appreciated.
Thanks to all who replied. It turned out to be an issue with the XCode rather than anything wrong with my code. Apparently, when I was typing the code in, I was interrupted half-way into typing, so that error message was valid (at the time). Then, about an hour later I came back to it and completed typing - but for some reason XCode was stuck on this error message.
I did 'clean', then 'build' - didn't help. So I did 'clean' again and then closed project. When I reopened the project and did 'build' again - the error wasn't there any more.
Strange problem. Try the following:
Try another name for your property (maybe it is a keyword/name used elsewhere, namely in any of Apple's framwork or similar - you could try command-clic on the word to see if Xcode finds its definition anywhere else than in your header file maybe?)
Be sure there is no hidden (non-printable) character
Try another place for your #synthesize, moving it one or two lines below, to check if the error comes from this very property or the one above it
[EDIT] Did't see this in your screenshot the first time, but it seems you have a semicolon right in the middle of your #synthesize shouldProcessVenueListRequ;est;, between the 'qu' and the 'est'... or is it the Fix-it proposition?
Check your code to ensure a few things
There is no space between shouldProcessVenueListRequ and est (even I thought you had a ; in there between the two parts :)
If you are copy-pasting the variable name from some place, you might want to type it all out manually (as Ali suggests, there might be a hidden character)
Try doing a clean-build
Even I got the same problem. When I checked it out, I gave the same name for variables but in different files. I just gave different names for all the variables, like if I have used a variable coupon in more than one file, I made it one as couponDisplay in one and couponList as another.

Request for member which is of non-class

I've got a C++ class I want to use which has all the code in the header file, rather than the CPP file. I'm trying to call it from an objective-C file which inherits a UIViewController class. I've renamed the file to .mm and imported the header file for the C++ file. When I compile, I keep getting a compile-time error when I try and access a method from the C++ class saying Request for member '<method>' in '<objectName>' which is of non-class type '<C++ class name>'. I did a search and it seemed that the header was usually the issue, but I've included the header in my file. What else could it be? (I can include generic code if required, but the I'm not sure if I'm allowed to show the actual code since it belongs to a third party).
The problem is likely in the declaration of the object that gives you the error, not in the header file. Sometimes the problem is hard to spot, you'll have to share some code if you can't figure it out by yourself.
I'm not a C++ coder, so this was probably an obvious mistake, but if anyone else comes across a similar problem, I simply changed my code from:
myObject.method();
to
myObject->method();

Thousand of errors in base classes like NSObject.h,NSObjCRuntime.h

I don't know why its happening .... I an integrating a twitpic api and its working fine all the projects except one. I am getting 5488 errors and that too in classes like NSObject.h and NSObjCRuntime.h . This api has a folder named Crypto which has two .c files in it, when i remove this folder from my project then the error decreases to 1 (because one of the class from this folder is used else where).All 5k+ errors are in these two class only, errors are like
FOUNDATION_EXPORT Class NSClassFromString(NSString *aClassName);
expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
few errors are
expected identifier or '(' before '#' token
expected identifier or '(' before '-' token
expected identifier or '(' before '+' token
One thing i am sure of is that there is no error in the classes because the same code is working good in other projects.
One more thing to mention is that I have two .pch and there is no effect of removing one of them.
compile the files as objc, not c
Usually these errors are caused by a problem in the .pch file, like an #import that doesn't belong, or something similar.
I got this error several times. This could happen because of superfluous curly bracket. Like
- (void)a {
}
}
Check latest changes in a project.

iphone error: expected '=', ',', ';', 'asm' or '__attribute__' before ' 'foo'

I'm trying to port the speakhere example into another app and I'm having issues. I copied all the files, and all the frameworks, but for some reason I get a bunch of compile errors that I've never seen before and thus don't know what to do. The only difference is that i'm not suing IB and so i had to change it slightly.
What does error: expected '=', ',', ';', 'asm' or '__attribute__' before 'foo' mean?... I get this error multiple times for different files
In my situation the first error is pointing at 'MeterTable'.. a class that includes <stdlib.h>,<stdio.h> and <math.h>. But those files seem to be importing fine (if i remove them i get more errors)
Any suggestions on how to debug this?
TIA!
EDIT:
I still can't seem to figure it out. I'm literally just copying files from the example into another project. Can someone check it out please ? SpeakHerePort.zip and the original is here SpeakHere.zip
Your problem is that you are compiling SpeakHerePortAppDelegate.m, which is an Objective C file, but it is indirectly including MeterTable.h which is a C++ header file.
Rename it to SpeakHerePortAppDelegate.mm (double m) so that it is compiled as Objective C++ and your problem is resolved.
Name all your files .mm and then all your code will be compiled as Objective C++
In my case, the .h and .m in question are built fine with regular target, and the App can run as well.
However after the subset of the files are moved under a static library target, it gets this compile error when the static library is built.
Was stuck for a while & tried the above mentioned techniques, unfortunately they didn't help in my case.
Noted that this error happened only for the NSString*, for e.g.,
extern double const kTimeout; // fine
extern NSString* const kImageType; // compile error
After the above analysis & little break, eventually the problem is resolved by adding the the following import to the .h - "Foundation/Foundation.h"
It sounds like an unfinished declaration, probably in a header file. Search for 'foo' (or whatever the symbol actually is) across all project files, using ⇧⌘F (Edit ▸ Find ▸ Find In Project...) in Xcode, and/or examine the headers you're including where MeterTable is declared. Sometimes the compiler gets confused about the actual location of the error, since header files are frequently #imported into other files, so the problem can be manifest in multiple locations.
This might not have applied to this exact situation, but I had this exact error too, which was caused by a bad forward declaration. In Objective-C, make sure your forward-declares begin with the # sign - e.g.
#class MyClass;
Those of us still on autopilot from C++ will forget the #, see that XCode has highlighted class as a reserved keyword, and think all is well with the world. It is not.
It means that you have a syntax error. If you paste the code in question, it's easier to debug.
I had a similar scenario to some of the posts above. I'd written a C++ class based off of the examples in the Audio Queue Services documentation, and had this compilation issue in a test project. This post helped a tremendous amount.
Today, I'm incorporating the C++ class in my project, and got the build error again. In my scenario, I had to also set the type (using the "Get Info" window) to sourcecode.cpp.objcpp for the objective-c class that was calling my C++ class.