xcode objective c missing #end on NSObject - objective-c

I've been racking my brains for the past 2 hours regarding this issue and I couldn't find any solution through searching or by removing the imported files of my CustomTableCell.
Here's my class (.h)
#import <UIKit/UIKit.h>
#interface MatchTableCell : UITableViewCell{
}
#property (nonatomic, weak) IBOutlet UILabel *matchId;
#property (nonatomic, strong) IBOutlet UILabel *fighter1Name;
#property (nonatomic, weak) IBOutlet UILabel *fighter2Name;
#property (nonatomic, weak) IBOutlet UILabel *status;
#end
This is what's popping up:
Missing '#end' .. this is popping up on the #interface line
Expected Identifier or '(' .. this highlights the first property
Thoughts?
EDIT: Solution. Apparently I can't post this as an answer even though that's how I solved the issue. Anyway, just in case it helps anyone, check the imports of the ViewControllers (or objects) that imports the file getting the error
Well, that was very tedious. Found a ViewController that is imported by a second viewcontroller, this second viewcontroller imports this NSObject. The first viewcontroller, for some reason got changed from UITableViewController to UIViewController. Thanks to #rob-mayoff for the idea

You are missing the #end directive at the end of one of your other .h files. Go through the .h files in your project one by one. For each one that has an #interface or #protocol section, make sure the section is terminated with an #end directive.

Also to mention that start with checking the recently added files. XCODE starts to show this error any where but doesn't indicate which file is missing the combination of #interface and #end. One of the file will have it missing.

Related

Cannot find protocol declaration for "XXXX"

I am stuck with this problem. I have the following .h file:
#import <UIKit/UIKit.h>
#protocol MapSettingsViewDelegate
- (void)settingsDidUpdate:(BOOL)scheme;
#end
#interface MapSettingsViewController : UIViewController
#property (nonatomic, assign) id <MapSettingsViewDelegate> delegate;
#property (nonatomic, strong) IBOutlet UINavigationBar *navBar;
#property (nonatomic, strong) IBOutlet UINavigationItem *titleItem;
#property (nonatomic, strong) IBOutlet UITableView *TableView;
- (id)init;
- (IBAction)saveAction:(id)sender;
#end
When I declare the following:
#interface MapViewController : UIViewController <MapSettingsViewDelegate>
The compiler complains with the following message:
Cannot find protocol declaration for 'MapSettingsViewDelegate'
I have the same kind of delegate declaration in other files in the same project that are compiled without a glitch. I spent the last four hours trying to figuring out what I am doing wrong. Cleaning the project does not nothing.
Problem solved. As suggested in this answer, I created a new class with a different name and copied all coded from the previous class. Worked flawlessly. It seems XCode lost track of something.
You are running into preprocessor problems. Both of your classes import each other. I think you can solve this by adding #class below your protocol declaration as shown below; and moving your #import "mapViewController.h" line into MapSettingsViewController.m file. The #class tells the compiler that you will include the class content somewhere else (in the .m file).
Note that, on the top of your MapViewController.h class file you can include #import "MapSettingsViewController.h" just like normal. Hope this help. I ran into the same problem myself earlier.
#import <UIKit/UIKit.h>
#protocol MapSettingsViewDelegate
- (void)settingsDidUpdate:(BOOL)scheme;
#end
#class MapViewController
#interface MapSettingsViewController : UIViewController
#property (nonatomic, assign) id <MapSettingsViewDelegate> delegate;
...
...
Import the MapSettingsViewController.h file

Error: Expected ; at end of declaration list - Class not recognized as type

Here is my viewcontroller.h file:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <CoreLocation/CoreLocation.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreMedia/CoreMedia.h>
#import <ImageIO/ImageIO.h>
#import <CoreVideo/CoreVideo.h>
#interface ViewController : UIViewController <UINavigationControllerDelegate, CLLocationManagerDelegate>
#property (nonatomic, strong) NSManagedObjectContext *managedObjectContext;
#property(nonatomic, weak) IBOutlet UIImageView *selectedImageView;
#property(nonatomic, retain) IBOutlet UIImageView *vImage;
#property(nonatomic, retain) AVCaptureStillImageOutput *stillImageOutput;
- (IBAction)photoFromAlbum;
- (IBAction)photoFromCamera;
- (IBAction)saveImageToAlbum;
- (IBAction)segueToChoosePhotoTypeViewController;
#end
The line:
#property(nonatomic, retain) AVCaptureStillImageOutput *stillImageOutput;
is generating the following issue:
Expected ; at end of declaration list.
Xcode isn't recognizing AVCaptureStillImageOutput as a class as it remains black and doesn't suggest it as a type, and the "Fix-it" wants to insert the ; right after AVCaptureStillImageOutput.
However, if I try to use declare AVCaptureStillImageOutput as a type in viewDidLoad of my viewController.m file, it recognizes it and allows it as a type. Also, the rest of the AVFoundation classes are being recognized in the code there.
The framework is there, I'm just having an issue with this #property declaration.
In your line
#property(nonatomic, retain) AVCaptureStillImageOutput *stillImageOutput;
you have some invisible characters between AVCaptureStillImageOutput and *stillImageOutput. If I paste this line into the vi editor, it looks like this:
#property(nonatomic, retain) AVCaptureStillImageOutput<feff><feff><feff><feff><feff> *stillImageOutput;
(U+FEFF is a Unicode Byteorder marker, and it looks like a normal space in Xcode, even if "Show Invisibles" is activated).
Deleting and re-inserting the space fixes the problem.
Go to the Editor menu, select Show Invisibles. Note that you have plenty of invisible, non printable characters between the AVCaptureStillImageOutput and the *. Delete everything between these two and finally put there a single space again. Those invisible characters, even though not printable, were taken as part of your class name. Once you are done, you can select Hide Invisibles again. Be careful when copy/pasting code, you even copy/pasted those "bad characters" into your SO question above.

Unknown Type Name in Xcode (even with #class declaration)

I'm having trouble with a simple app setting up a data controller. I get an error on the line #property (strong, nonatomic) BirdsListDataController *dataController; in BirdsListViewController.h. I've tried my best to use a #class declaration of BirdsListDataController, as well as trying to remove any #import statements from the .h files and tried to remove a circular #import which you can find commented out in the top of BirdsListViewController.h. I'm guessing it's something simple.
BirdsListViewController.h
#import <UIKit/UIKit.h>
#class BirdsListDataController;
#interface BirdsListViewController : UITableViewController <UITextFieldDelegate>
{
// NSMutableArray *listOfBirds;
IBOutlet UITextField *addNewBirdTextField;
}
//#property (nonatomic, retain) NSIndexPath *checkedIndexPath;
#property (nonatomic, retain) NSString *textLabelContents;
#property (nonatomic, retain) NSMutableArray *workingArray;
#property (strong, nonatomic) BirdsListDataController *dataController;
#property (strong, nonatomic) IBOutlet UITableView *birdListTableView;
#end
BirdsListViewController.m
#import "BirdsListViewController.h"
#import "BirdsListDataController.h"
#interface BirdsListViewController ()
#end
#implementation BirdsListViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
...
BirdsListDataController.h
#import <Foundation/Foundation.h>
#class BirdName;
#interface BirdsListDataController : NSObject
#property (nonatomic, copy) NSMutableArray *listOfBirds;
-(NSUInteger)countOfList;
-(BirdName *)objectInListAtIndex:(NSUInteger)theIndex;
-(void)addBirdNameWithName:(BirdName *)bName;
#end
BirdsListDataController.m
#import "BirdsListDataController.h"
//#import "BirdsListViewController.h"
#import "Bird.h"
#implementation BirdsListDataController
-(id)init
{...
I'm still really new to iOS and Objective C, so hopefully my code isn't too awful to troubleshoot. Thanks for the help.
For people looking for a better answer than comment/uncomment your code, a better solution is to clean your project and to delete your derived data. Once you've fixed your circular references, the keystroke Command+Shift+K will clean your project, or you can go to and select Product->Clean.
To delete your derived data, open Organizer, click on the Projects tab, navigate to your project in the sidebar. You should see "Derived Data" under the project name header. To the right of that should be a button saying delete. If it is enabled, deleting the derived data can also remove hanging errors.
As way of explanation, it seems sometimes that Xcode becomes out of sync with a project, holding on to errors that no longer exists. This is better in more recent version, but still happens occasionally.
I'm not certain what is causing your problem, but a few things:
In the code that you've presented there is no reason not to import BirdListDataController.h in BirdListViewController.h, since there is no reference to BirdListViewControllers in BirdListDataController.h. So try replacing your #class declaration with an #import statement.
In BirdListDataController.h you declare #class BirdName, but in BirdListDataController.m you import Bird.h instead of BirdName.h. It seems like something could be wrong there, although I would have to see the code for BirdName.h and Bird.h to know for sure.
In my case I had duplicate class names in different folders structure, Once I removed the new class and named it differently everything worked again.
So to translate this into a practical solution, as per "shA.t"'s comment:
if you comment/uncomment your code, or clean project as above
answers suggested but still doesnt solve it:
take a step to look back at recent classes changes and double check
all class names are unique even if in different directories, double
check
them all
if duplicate class name found: make a backup of that
code, delete that class (not just reference, but to trash too)
create a new class with unique name and incorporate the backed up
code
For this particular duplicate class name scenario, this will save you the hassle of importing and commenting your #import "class.h"

Beginner struggling with Objective-C

I'm following an objective-c book (objective-c fundamentals by Fairbairns, Fahrenkrug, Ruffenach), and I've fallen at the first hurdle with their CoinToss example.
I'm getting an 'expression expected' error on this line:
result.text = coinLandedOnHeads ? #"Heads" : #"Tails";
I have also included a screenshot of the whole page below.
What exactly is the problem? I've checked and double checked the code is the same as the book, but have I missed something very obvious?
Thanks!
EDIT:
Here is my header file:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
UILabel *status;
UILabel *result;
}
#property (nonatomic, retain) IBOutlet UILabel *status;
#property (nonatomic, retain) IBOutlet UILabel *result;
-(IBAction)callHeads;
-(IBAction)callTails;
#end
I know your problem exactly.
The book is outdated. When you created the project you had the tick box 'Automatic reference counting' selected. That means, you don't have to do the dealloc. It's not your fault, Xcode just has a new automatic memory management capability, and the book is old enough so that it's making you do it manually.
To fix it:
Remove the dealloc method entirely
Or,
Restart your project and don't tick the 'Automatic Reference Counting' tick box.

unknown type name in objective c

I'm pretty new to objective c, and having some basic problems.
I wrote a simple program using a navigator, and everything worked fine.
then I added few lines of code (can't even remember what exactly, and it seems to have no connection to the problem) and the problem occurred. I tried ctrl+z, and the problem remained:
I run the program and get these errors:
1. unknown type name "mainController"
2. property with 'retain (or strong)' attribute must be of object type
while mainController is the first screen to be loaded.
This is the appDelegate.h file:
#import <UIKit/UIKit.h>
#import "mainController.h"
#import "WishesList.h"
#import "Wish.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) IBOutlet UINavigationController *navController;
#property (strong, nonatomic) IBOutlet mainController *viewController; // this line creates the errors
#property (strong, nonatomic) WishesList *WishesArray;
#property (strong, nonatomic) NSIndexPath *temp;
#end
this is the relevant part of the appDelegate.m file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
WishesArray = [[WishesList alloc]init];
temp = nil;
[self setViewController:[[mainController alloc]init]];
[self setNavController:[[UINavigationController alloc]initWithRootViewController:self.viewController]];
[self.window setRootViewController:navController];
[self.window makeKeyAndVisible];
return YES;
}
And this is mainController.h:
#import <UIKit/UIKit.h>
#import "addWishController.h"
#import "displayWish.h"
#import "WishesList.h"
#import "Wish.h"
#interface mainController : UIViewController
#property (nonatomic, weak) WishesList *list;
#property (nonatomic, strong) IBOutlet UITableView *wishTable;
- (void)addWish;
#end
it already worked...
can you figure it out?
thanks
I figured out, that the same error appears if you have an import-cycle:
Class_A.h: #import "Class_B.h"
Class_B.h: #import "Class_A.h"
To fix: look for any imports of the offending class (the error tab is your friend, expand the relevant error for a list of imports). Remove #import's accordingly
This problem happen to me once.
I was importing the "APPDelegate.h" in my h file and in my APPDelegate.h I was importing the file too (it shouldn't be a problem but...)
What I did: I changed the Import from my own .h to .m and it worked :)
As others have mentioned, this is indeed caused by cyclic imports. To fix this remove the imports in one of the classes. But sometimes this is not sufficient. If the classes depend on each other, simply forward-declare the one class in the other:
Class A:
#import <UIKit/UIKit.h>
#class B; //<- this is essential here
#interface A: NSObject
#property(nonatomic, strong) B *b;
//...
In class B we have:
#import "A.h"
#interface B: NSObject
#property(nonatomic, strong) A *a;
#JustAStranger and #NathanielSymer, both are correct!
Anyway, worth remember that this case, below, has the same problem too:
Class_A.h: #import "Class_B.h"
Class_B.h: #import "Class_C.h"
Class_C.h: #import "Class_A.h"
This problem reveal to us how important is take care about owners at our Class relationships. Is very easy creates cycle problems using ObjC headers.
Check the target and the files it is compiling. Perhaps mainController has some how been removed from that target. If so, when building, you would get the message that it cannot be found.
This problem looks like a typo because class names usually start with an uppercase character. Therefore, mainController could/should be MainController. Check the class name to see if the error is indeed a typo, because the compiler is telling you it cannot find any class called mainController.