Expected identifier or '(' error before #class - iphone

I have these 2 classes:
ViewController.h
#import <UIKit/UIKit.h>
#import "UICustomButton.h"
#interface ViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>{
...
ViewController.m
#import "ViewController.h"
#implementation ViewController
...
UICustomButton.h
#import <UIKit/UIKit.h>
#class ViewController;
#interface UICustomButton : UIButton{
...
UICustomButton.m
#import "UICustomButton.h"
#import "ViewController.h"
#implementation UICustomButton
...
And I get the following errors
1 Expected identifier or '(' - in file UICustomButton.h just before #class
2 Expected ')' - also there
3 Expected a type - when I try to use ViewController in UICustomButton.h
4 in UiCustomButton.m I also get the error
After two hours of googling and trying, I just can't see the problem. Can you please help?
SOLUTION:
Rewriting everything was a good ideea. It made me see that in the file ViewController.m I had accidentally typed a paranthesis '(' on top at the beginning of the file. The compiler didn't poit it out, only UICustomButton.H generated errors.

Don't be afraid to restart/scrap and recreate a class. As you gain more experience correcting complex errors becomes a lot easier.
I'm completely serious about you needing to restart creating this class. Since apparently you can't interpret the message that the compiler is telling you it will take much longer for you to figure out the issue than creating another class, copying the business logic there and deleting the current implementation. Your choice, spend 10 minutes recreating the file or spend another who knows many hours trying to get the syntax Ok.
Even the professionals feel it a strong tool to restart when it's needed. Marshall Huss from Treehouse explains in this podcast why it was preferrable for him too.
PS: and best, you can rename the new class to the old name once you're done.

Looks like you are misspelling ViewController.h. You have Viewcontroller.h in your #import line

Related

Would these two generate the same compile time?

I know that #class is suppose to speed up compile time, but if I had a case like this:
#import <Foundation/Foundation.h>
#class BNRItem;
#interface BNRItemStore : NSObject
#end
#import "BNRItemStore.h"
#import "BNRItem.h"
#implementation BNRItemStore
#end
Could I do this instead and still get the same compile time:
#import <Foundation/Foundation.h>
#import "BNRItem.h"
#interface BNRItemStore : NSObject
#end
#import "BNRItemStore.h"
#implementation BNRItemStore
#end
(assuming you actually use BNRItem someplace in these files)
it would be the same for BNRItemStore.m, but it is likely to increase compile times and recompilation frequency for anything that #imports BNRItemStore.h -- because it's common that many classes that need to see BNRItemStore do not need to also see BNRItem's #interface.
as that pattern spreads to many headers in your projects, a simple edit to one header can require recompiling a large set of files, with a large set of included files. it also spreads to the indexer, which is continually indexing based on changes.
best to use the forward declarations, unless your project is (and will remain) tiny.
it's actually really nice to be able to declare all your instance variables/properties in the .m -- as this is a fairly new addition to clang. abstraction and build times can improve significantly.
Yes and no.
You wouldn't get the SAME at compile time. #class just tells the compiler its going to see that class, so treat it as a class (take it out, and you get errors) whereas #import tells the compiler to completely import the .h (header) file for that class.
So it will be slower (as you've suggested), especially if the .h (header) file for the class #imports any other files. For an interface you don't need all that functionality, you just need the definition.
But to all intents and purposes the perceived functionality as far as you are concerned is exactly the same, so yes in that respect.

Unknown Expected identifier

I have taken over a project and am fairly new to cocotouch. I was looking throught the code trying to understand things. I didn't think I changed anything but when I went to run It came up with three build errors (it had run just a few minutes before with no problems). The second two seemingly related to the first:
#import <UIKit/UIKit.h>
#protocol MapViewDelegate; //Expected identifier or '(' before 'protocol'
#interface MapView : TTImageView
{
id<MapViewDelegate> mv_delegate; //Cannot find protocol declaration for 'MapViewDelegate'
}
#property (assign) id<MapViewDelegate> mv_delegate; //Cannot find protocol declaration for 'MapViewDelegate'
#end
#protocol MapViewDelegate <NSObject>
- (void)mapView:(MapView *)mv pressedAt:(CGPoint)point;
- (void)mapViewFinishedLoading:(MapView *)mv;
#end
I am using XCode4 which I have just switched to but have had working since the switch.
What is going on here?
MapKit.framework has been added to the project?

Protocol definition not found

I am having a little trouble with getting a protocol definition to work, and this must be a stupid mistake. I included the header in which the definition is located, but I got the warning, so followed the advice to create a separate header file. I still get the warning that the definition cannot be found (when importing this separate file), and even when I put the definition in the header file of the class using it it gives the warning:
#protocol SubstitutableDetailViewController <NSObject>
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
#end
#interface LauncherViewController :TTViewController<SubstitutableDetailViewController, TTLauncherViewDelegate> {
TTLauncherView *launcherView;
}
So what do I do wrong in my definition of the protocol?
[EDIT: Sorry, there must be an oddity in Xcode, or I am going mad, I did a clean build and now the warning does not come back... but I don't know why]
Put this code in a separate file named SubstitutableDetailViewController.h (I'd prefer SubstitutableDetailViewControllerDelegate.h):
#protocol SubstitutableDetailViewController <NSObject>
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
#end
And then include it in LauncherViewController via #import "SubstitutableDetailViewController.h"

The same error i all headers - error: expected '='... before 'protocol'

I've been working on an iOS project for some time but now I have an error which really confuses me and as long as I can't fix it I can't even compile the project so I need some serious help!
It all began with an:
error: expected '=', ',', ';', 'asm' or 'attribute' before 'protocol'
in PHCluesListViewController.h. The class had not been changed for a long time and what I was working on at the moment of the error had nothing to do with that particular class.
This is what it looks like:
#import <UIKit/UIKit.h>
#protocol PHCluesListViewControllerDelegate;
#class PHClueListTableViewController;
#interface PHCluesListViewController : UIViewController {
IBOutlet PHClueListTableViewController *clueListTableViewController;
id <PHCluesListViewControllerDelegate> delegate;
}
- (void)mapDelegate;
#property (nonatomic, assign) id <PHCluesListViewControllerDelegate> delegate;
#end
#protocol PHCluesListViewControllerDelegate
- (void)mapUp:(PHCluesListViewController *)controller;
#end
There are no syntax errors and there is nothing wrong with the code in it's context either. Later I would learn that if you were to take away all the code from the header file the error would move to a another random header file or if you were to import another header the error would move to this header.
I've tried to restart xcode, to move the project to a new one, to rewrite the code to a new file and to move the project to another computer with another version of xcode - but with no luck.
I am able to run other xcode-projects on my computer.
It seems to me that xcode are trying to compile my headers in this specific project in some unwanted fashion.
Help would be highly appreciated, thanks on before hand!
---------- EDIT!!! ----------
Thanks for the fast respond!! Although I've found the answer.
The error was a "d" written out of bounds of the implementation in a totally different file/class. Found it by chance...
If something similar would happen to anyone else; check for something like a letter written after #end or before #interface/#implementation or anything else that would "cut the edges" of the common syntax.
It's difficult to find the reason for an error like this and I'm a little bit surprised that I found it so quickly among 80 files (only 4.5 hours).
Good luck!!
You're defining #protocol PHCluesListViewControllerDelegate twice. Also, if mapUp is required to be implemented, you might want to add the #required keyword.

Expected Specifier qualifier list error

Hey guys, I know this problem caused due to the absent of importing header
But in my case, I've included the header but I still got the error?! What happens?
#import <Foundation/Foundation.h>
#import "WikitudeARCustomMenuButtonDelegate.h"
#import "DetailedARViewController.h"
#interface CustomMenuButtonDelegateImpl1 : NSObject <WikitudeARCustomMenuButtonDelegate>
{
DetailedARViewController *ARViewController;
}
#end
Make sure that "DetailedARViewController.h" really does define DetailedARViewController; in particular, check for subtle errors like misspellings or a declaration accidentally commented out.