Expected specifier-qualifier-list before error - objective-c

#import <UIKit/UIKit.h>
#import "NotepadViewController.h"
#import "NotesTableViewController.h"
#import "NoteInformationTransferProtocol.h"
#interface NotesViewController : UIViewController <NoteInformationTransferProtocol>
{
UITextField *_noteTitleTextField;
UIButton *_addButton;
UITextField *_description;
UIView *_notesTableView;
NotepadViewController * _notepadVC;
NotesTableViewController *_noteTableVC;
}
I am getting the error "Expected specifier-qualifier-list before NotepadViewController" on "NotepadViewController * _notepadVC;" I already imported that class' header so it should detect it as a type, right?

That error normally occurs when you haven't added a framework or file to your target, is "NotepadViewController.h" in the target you are building?
In xCode 4 you can check this by expanding the "Compile Sources" section in Build Phases.
In xCode 3 you can use "Get info" to see what targets that file is included (if my memory serves me true)

Related

iOS 8 Expected a type

I have the UIScrollViewSlidingPages and the SSPullToRefresh libraries in a lot of projects, but suddenly, I'm getting this weird errors in this new iOS 8 project.
#import <Foundation/Foundation.h>
#interface TTSlidingPageTitle : NSObject
-(id)initWithHeaderText:(NSString*)headerText;
-(id)initWithHeaderImage:(UIImage*)headerImage;
//The title text to go in the nav bar
#property(strong, nonatomic) NSString *headerText;
//An image to use in the nav bar (if you set this, the title text will not be used)
#property(strong, nonatomic) UIImage *headerImage;
#end
This line is getting the "Expected a Type" error:
-(id)initWithHeaderImage:(UIImage*)headerImage;
And this line is getting the "Unknown type name UIImage" error:
#property(strong, nonatomic) UIImage *headerImage;
If you check the docs for UIImage you'll see it's in UIKit, not Foundation. The docs are now all targeted at Swift, which is somewhat annoying, but you'll see the import statement in the docs is specified as
#import UIKit;
which you need at the top of your file (no need for the Foundation import either).
Sometimes projects include this import statement in a precompiled header file (pch). This should be referenced in Build Settings->Prefix Header, or it won't be used in compilation.

CLLocation can't be found even though <CoreLocation/CoreLocation.h> is imported

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#interface SomeClass : NSObject
{
CLLocation *location;
//...
}
//...
Code seems okay, right?
But I still get "Unknown type name 'CLLocation'", even though CoreLocation.framework is imported to "Link Binary with Libraries" and CoreLocation.h is imported.
This error occured after I added a new target to the project - "Cocoa Touch Unit Testing Bundle". CoreLocation.framework is imported to this target, too.
Removing and adding the framework back is the best solution through which i solved a same problem.Also make sure you have added framework to unit test project.

Delegate in a static library not working in Xcode

I made a class that uses the delegate pattern and I put it in a static library. Then, I created a demo app to test the library. The demo just has a single view controller, and in the .h file, I have this:
#interface ViewController : UIViewController <AuthenticationDelegate>
#property (nonatomic, retain) IBOutlet UITextField *usernameTextField;
#property (nonatomic, retain) IBOutlet UITextField *passwordTextField;
#end
When I compile, I get an error right on the first line of the file that says:
Cannot find protocol declaration for 'AuthenticationDelegate'.
But, in the .m file for the same view controller, I have:
#import "Authentication.h"
#import "ViewController.h"
The file "Authentication.h" is the only header file in my static library, and it does declare the delegate class:
#class AuthenticationProvider;
#protocol AuthenticationDelegate <NSObject>
#optional
- (void)provider:(AuthenticationProvider *)provider didReplyWithResponse:(AuthenticationProviderResponse)response;
#end
Where am I going wrong?
Update:
If I put #import "Authentication.h in ViewController.h, I get this:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_AuthenticationProvider", referenced from:
objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I get that when I remove #import "Authentication.h from ViewController.m also.
Try #import "Authentication.h" in your classes .h file, not your .m file

How does it compile? How can the compiler find the declaration of NSFetchedResultsController, when there is no obvious import statemetn?

I make my first steps in objective-c and cocoa. I typed in the following example class, which compiles well in the iPhone main project. When I use the sample class in an OCUnitTest, the compiler raise an error.
class:
#import <UIKit/UIKit.h>
#interface ProjekteTableViewController : UITableViewController {
NSFetchedResultsController *fetchedResultsController;
}
#property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
#end
Now the question: I see in UIKit.h no direct or indirect #import for the NSFetchedResultsController.h file.
How does the compiler resolve this identifier (NSFetchedResultsController) ?
I expected the compiler error not only in the UnitTest project, but also in the main project.
I suspect you've got a prefix header that's including CoreData.

Objective-C not recognizing .h?

I have the following in a project named testApp: (testAppViewController is the valid name of my view controller in the project)
PrevView.h
#import <UIKit/UIKit.h>
#import "testAppViewController.h"
#interface PrevView : UIView {
testAppViewController *viewController;
}
#property (nonatomic,retain) testAppViewController *viewController;
#end
When I build the project I'm getting the following error:
PrevView.h:13: error: expected specifier-qualifier-list before 'testAppViewController'
Am I missing something here? Any ideas?
Does "testAppViewController.h" import "PrevView.h"?
If so, you may want to delcare a forward class reference:
#class testAppViewController;
that replaces the import you have, and move the import into the .m file.
Usually when I see this type of error, it's a problem in the header file that you're trying to import. Check "testAppViewController.h"