objective-c 2.0 Duplicate interface definition for class when defining private methods - objective-c

i try to define simple private methods and properties in class but it gives me:
Duplicate interface definition for class 'FBViewController'
this is the .m file :
#import "FBAppDelegate.h"
#import "FBViewController.h"
#import<FacebookSDK/FacebookSDK.h>
#import "FBLoginViewController.h"
#interface FBAppDelegate()
#property (strong,nonatomic) UINavigationController *navController;
#property (strong, nonatomic) FBViewController *mainController;
-(void) showLoginView;
#end
#implementation FBAppDelegate
#synthesize navController = _navController,
mainController =_mainController;
...
...
#end
and this is the *.h file:
#import <UIKit/UIKit.h>
#interface FBAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
UPDATE
added the import files
*SOLVED *
in FacebookSDK there is FBViewController.h already

The error you are getting is
Duplicate interface definition for class 'FBViewController'
And you are looking to class called FBAppDelegate. Try reading the error message again, it may help.

Related

property not found on object of type error but property is there

So I'm trying to access the property isPortClosed(BOOL) in SerialPortController and its giving me an error, I'm kinda new to objective-c. I feel like this should work as I've got a reference to the class with *port. Here is a link to the project.
Error messages: ~/GroundStation/GroundStation/ViewController.m:16:22: Property 'isPortClosed' not found on object of type 'SerialPortController *'
#import <Cocoa/Cocoa.h>
#import "SceneView.h"
#import "SerialPortController.h"
#interface ViewController : NSViewController
#property (strong) IBOutlet SerialPortController *port;
#property (weak) IBOutlet SceneView *accelSceneView;
#end
#import "ViewController.h"
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
while(!self.port.isPortClosed) {
}
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
#end
SerialPortController.h class
#import <Foundation/Foundation.h>
#import <ORSSerial/ORSSerial.h>
#interface SerialPortController : NSObject <ORSSerialPortDelegate>
#property (nonatomic, strong) ORSSerialPort *serial;
#property (nonatomic, strong) ORSSerialPortManager *serialPortManager;
#property (nonatomic) NSInteger xAngle;
#property (nonatomic) NSInteger yAngle;
#property (nonatomic) NSInteger zAngle;
#property (nonatomic) NSString *stringBuffer;
#property (nonatomic) BOOL isPortClosed;
#end
From the downloaded project I see that you have two SerialPortController class definitions (one at the root directory, and one in /GroundStation/), and the latter doesn't have any public properties. You should have only one SerialPortController class definition linked in your project (the one with the public properties).

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

#end in c-objective

Ok, it may be a dumb mistake. But I can't figure out what xcode wants from me.
So here is the header file
#import <Foundation/Foundation.h>
#import "TableViewController.h"
#end
#interface Settings : NSObject
- (id)init: (TableViewController*) TableControll;
#end
If there is no #end before interface it says expected identifier or (, and suggests adding #end there. If there is an #end it says end must appear in objective-c contex.
Ideas?
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
#interface TableViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,MFMessageComposeViewControllerDelegate>
{
ControllerType controllerType;
}
#property (retain, nonatomic) IBOutlet UITableView *tableView;
#property (retain, nonatomic) NSArray *dataArray;
#property (retain, nonatomic) NSArray *imageArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andType:(ControllerType)type;
#end
You have a #end before the #interface declaration in your Settings.h file.
It should read:
#import <Foundation/Foundation.h>
#import "TableViewController.h"
#interface Settings : NSObject
- (id)init: (TableViewController*) TableControll;
#end
Also, you haven't included the #import directive for ControllerType in your TableViewController.h which may be why you're getting obscure errors in your Settings.h file.

iOS 5.0 Warning: Cannot find protocol definition for Delegate

I have custom UIView class GestureView. I have a forward declaration for this class and it's delegate below. I have imported GestureView.h in .m file. This works fine but iOS gives warning message saying "Cannot find protocol definition for GestureViewDelegate". If I remove forward declaration it gives same warning message as error. I don't want to import GestureView.h from ContainerViewController.h as I usually imports stuffs in .m file. Could someone please explain what's wrong in following class structure?
ContainerViewController.h
#import <UIKit/UIKit.h>
#class DividerView;
#class GestureView;
#protocol GestureViewDelegate;
#interface ContainerViewController : UIViewController<GestureViewDelegate>
#property (strong, nonatomic) IBOutlet GestureView *topContentView;
#end
GestureView.h
#import <UIKit/UIKit.h>
#protocol GestureViewDelegate;
#interface GestureView : UIView
- (void)initialiseGestures:(id)delegate;
#end
#protocol GestureViewDelegate <NSObject>
#required
- (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer;
#end
I like that you're trying to avoid imports in header files: very good practice. However, to fix your bug you can just make your code even better! In my opinion it's not really necessary that your ContainerViewController class outwardly declares that it supports GestureViewDelegate protocol, so you should move this into your implementation file. Like so:
GestureView.h
#import <UIKit/UIKit.h>
#protocol GestureViewDelegate;
#interface GestureView : UIView
- (void)initialiseGestures:(id <GestureViewDelegate>)delegate;
#end
#protocol GestureViewDelegate <NSObject>
#required
- (void)gestureView:(GestureView *)view handleSingleTap:(UITapGestureRecognizer *)recognizer;
#end
ContainerViewController.h
#import <UIKit/UIKit.h>
#class GestureView;
#interface CollectionViewController : UIViewController
// this property is declared as readonly because external classes don't need to modify the value (I guessed seen as it was an IBOutlet)
#property (strong, nonatomic, readonly) GestureView *topContentView;
#end
ContainerViewController.m
#import "ContainerViewController.h"
#import "GestureView.h"
// this private interface declares that GestureViewDelegate is supported
#interface CollectionViewController () <GestureViewDelegate>
// the view is redeclared in the implementation file as readwrite and IBOutlet
#property (strong, nonatomic) IBOutlet GestureView *topContentView;
#end
#implementation ContainerViewController
// your implementation code goes here
#end
Try this way, and please reply if it works or not.
GestureView.h
#import <UIKit/UIKit.h>
#protocol GestureViewDelegate <NSObject>
#required
- (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer;
#end
#interface GestureView : UIView
- (void)initialiseGestures:(id)delegate;
#end
ContainerView.h
#import <UIKit/UIKit.h>
#class DividerView;
#class GestureView;
/*#protocol GestureViewDelegate;*/ //NO NEED TO WRITE THIS
#interface ContainerViewController : UIViewController<GestureViewDelegate>
#property (strong, nonatomic) IBOutlet GestureView *topContentView;
#end

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.