I'm trying to create a NSManagedObjectContext object. They error reads as follows:
Expected specifier-qualifier-list
before 'NSManagedObjectContext'
and here is my header file:
#import <UIKit/UIKit.h>
#interface FavouritesViewController : UITableViewController {
NSArray *favourites;
NSManagedObjectContext *context;
}
#property (nonatomic, retain) NSArray *favourites;
#property (nonatomic, retain) NSManagedObjectContext *context;
#end
Anyone know I might be missing here?
Most probably you have forgotten to include the CoreData header in your file. Right after the line #import <UIKit/UIKit.h> you need another line that reads #import <CoreData/CoreData.h>. After this the file should compile fine. Also make sure that you have CoreData in your linked libraries, otherwise you will get runtime errors.
You need to add #class NSManagedObject above your interface directive. This will tell the compiler that NSManagedObject is a real class. You then need to have #import <CoreData/CoreData.h> in your .m file.
Related
I have read question after question about people getting the same error as me, but I simply do not understand them, so before you go searching for duplicate questions, maybe someone can explain to me what I am doing wrong with this subclassing deal.
I have a subclass of UIImageView called swapView that I want to subclass to override the method -(void)count for special cases. I went to subclass this as I have any pre-existing UIKit class, but when I tried to build and run the project, I get this error:
Attempting to use the forward class 'swapView' as superclass of 'coinView'
I have tried putting both the #import statement of swapView and #class swapView in coinView.h and I've tried putting the import statement in coinView.m, but it refuses to build because of this continued error. If I move the import statement into the .m file, all references to the superclass's methods and properties, such as #property (nonatomic) int max; cause errors as well.
What am I doing wrong?
swapView.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#class ViewController;
#interface swapView : UIImageView
{
NSTimer* tmr;
}
#property (nonatomic) int current;
#property (nonatomic) int max;
#property (nonatomic, retain) UIImage* firstImage;
#property (nonatomic, retain) UIImage* secondImage;
#property (nonatomic) BOOL smallMax;
#property (nonatomic, retain) ViewController* pvc;
- (BOOL)testCollision:(CGPoint)point;
- (float)randomFloatBetween:(float)smallNumber bigNumber:(float)bigNumber;
#end
coinView.h
#import "swapView.h"
#class swapView;
#interface coinView : swapView
- (void)count;
- (void)move;
#end
For inheritance, the superclass MUST be inherited.
coinView.h
#import "swapView.h"
#interface coinView : swapView
- (void)count;
- (void)move;
#end
You're both forward declaring and importing ViewController.h in your swapView, which may cause compiler to complain.
swapView.h
#import <UIKit/UIKit.h>
#class ViewController
#interface swapView : UIImageView
.
.
.
#end
This is my code:
#import <UIKit/UIKit.h>
#interface CustomCellArticle: UITableViewCell
#property(nonatomic,retain) IBOutlet UILabel *name;
#end
In first time I received this error:
Missing #end
Expected identifier or '('
in the first of the code, and it required me to add #end in the first to fix it.
the code became like this:
#import <UIKit/UIKit.h>
#end //here the seconde error
#interface CustomCellArticle: UITableViewCell
#property(nonatomic,retain) IBOutlet UILabel *name;
#end
When I add it, I received a new error:
#end must appear in an Objective-C context
I don't know what's happened exactly, please help!
I used the same class in another project and it works fine!
Yes that is from a another header or implementation file already imported beforehand that is missing a #end
It could be a .h or .m file
#end should only come once in a single file.Whats with the top #end.And import all files at the top ?
you may have opened a "{" that is never closed with a "}" before the #end line...
so, the error is not at the #end line... but xcode just find out you are missing a "}" or ")"
Let me show whole file .h and .m file then i can answer well No Problem.
You need to remove first #end from .h file and run you will solve the issue.
Instead of this :
#import <UIKit/UIKit.h>
#end
#interface CustomCellArticle: UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *name;
#end
Use this :
#import <UIKit/UIKit.h>
#interface CustomCellArticle: UITableViewCell
{
}
#property (strong, nonatomic) IBOutlet UILabel *name;
#end
May this will help you. This is working fine for me.
I have checked also in xcode. You Just need to remove first #end.
If this thing is not working you have some another issue.
I am sure this is really dumb, but I just cant seem to understand why am I getting this error. In my project I have a view controller and another class that does some data structuring job (not relevant anyway). I am getting a compilation error: "unknown type name "the view controller"" when trying to instantiate it within my class.
This is my class .h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import "MyLocationController.h"
#import "GetZip.h"
#import "SecondTab.h"
#interface DataEngine : NSObject <MyLocationControllerDelegate, MKMapViewDelegate, GetZipcodeDelegate> {
MyLocationController *CLController;
GetZip *getzip;
SecondTab *secondTab; //ERROR IS HERE
}
My view controller .h:
#import <UIKit/UIKit.h>
#import "FirstTab.h"
#import "DataEngine.h"
#interface SecondTab : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *table1;
NSString *address;
NSDate *time;
NSDictionary *dataDict;
DataEngine *fullData;
}
(I omitted all the #synthesis since I dont think they matter...in any case, I do #property (nonatomic, retain) for everything).
Any idea what can go wrong here?
Why don't you try to forward declare it. Use #class secondTab instead of #import secondTab? It will help avoiding any circular inclusions if thats the problem.
I tried searching for this issue, but can't seem to find out what I'm doing wrong.
Here is my controller header:
#import <UIKit/UIKit.h>
#interface BabyLearnViewController : UIViewController {
UIButton *btnImage;
MediaManager* myMediaManager;
}
#property (nonatomic, retain) IBOutlet UIButton *btnImage;
#property (retain) MediaManager* myMediaManager;
- (IBAction)setNewImage;
#end
Here is my controller class:
#import "BabyLearnViewController.h"
#import "MediaManager.h";
#implementation BabyLearnViewController
#synthesize btnImage;
#synthesize myMediaManager;
I am getting the errors:
error: expected specifier-qualifier-list before 'MediaManager'
error: no declaration of property 'myMediaManager' found in the interface
Any ideas? Usually the 1st error comes up if you have a cylical reference. 'MediaManager' doesn't reference anything else. Any ideas?
Since you have no mentions of MediaManager class at the moment it is used in header file compiler can't figure out what "MediaManager" is and issues an error. Declare that class using forward declaration in your header file to let compiler know that MediaManager is actually a class:
#class MediaManager;
#interface BabyLearnViewController : UIViewController {
...
P.S. As an alternative you can import MediaManager.h in your header, but using forward declaration is preferred.
Place #import "MediaManager.h"
this in header file of BabyLearnViewController
try add #class MediaManager; before #interface
I am importing File "FieldActivityViewController.h".But Showing an error
"/Users/rupeshnandha/Downloads/AQMD
Release 3/Classes/InputChoice.h:22:0
Expected specifier-qualifier-list
before 'FieldActivityViewController'
in /Users/rupeshnandha/Downloads/AQMD
Release 3/Classes/InputChoice.h"
As is a code Written in "InputChoice.h"
#import "FieldActivityViewController.h"
#protocol InputChoiceProtocol <NSObject>
#required
-(void) inputChoiceSelectedIndex :(int) index;
#end
#interface InputChoice : UIViewController {
//NSString *keyString;
FieldActivityViewController *field_act;
NSMutableArray *selectionArray;
IBOutlet UITableView *table;
NSObject<InputChoiceProtocol> *delegate;
// IBOutlet UIPickerView *picker;
}
#property (nonatomic,retain) NSArray *selectionArray;
#property (nonatomic,retain) FieldActivityViewController *field_act;
#property (nonatomic,retain) NSObject<InputChoiceProtocol> *delegate;
#end
It's not the good practice to import the application classes in .h files.
Try with forward class declaration and import you FieldActivityViewController file in .h
Use with forward class declaration #class FieldActivityViewController; at the place of your import statement.
use #class FieldActivityViewController
Most likely cause is that you have a circular dependency. InputChoice.h imports FieldActivityViewController.h and FieldActivityViewController.h imports InputChoice.h (not necessarily directly).
The best solution is to move the imports out of the header file into the .m file and put
#class FieldActivityViewController;
in InputChoice.h and
#class InputChoice
in FieldActivityViewController.h (or whichever header has InputChoic.h in it.