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.
Related
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).
Please consider the following header (LessonDelegate.h):
#import "Lesson.h"
#ifndef BirdEye_LessonDelegate_h
#define BirdEye_LessonDelegate_h
#protocol LessonDelegate <NSObject>
- (BOOL) lesson:(Lesson*)lesson didRequestNavigation:(NSString*) url;
#end
#endif
It gives an error here:
- (BOOL) lesson:(Lesson*)lesson didRequestNavigation:(NSString*) url;
saying "Expected a type". It complains about Lesson type even if it is declared and successfully used in other classes.
Lesson.h is where it is supposed to be (same folder) and looks like this:
#import <Foundation/Foundation.h>
#import "SimpleManifest.h"
#import "Activity.h"
#import "LessonDelegate.h"
#interface Lesson : Activity
#property (retain, nonatomic) NSString *url;
#property (retain, nonatomic) SimpleManifest *manifest;
#property (retain, nonatomic, readonly) Activity *runningActivity;
#property (weak) id<LessonDelegate> delegate;
- (id) initWithUrl:(NSString*) aurl;
- (NSString*) deteails;
#end
Where's my mistake?
LessonDelegate.h
#class Lesson; // there was a missing ; here
#protocol LessonDelegate <NSObject>
- (BOOL) lesson:(Lesson*)lesson didRequestNavigation:(NSString*) url;
#end
Lesson.h
#import <Foundation/Foundation.h>
#import "SimpleManifest.h"
#import "Activity.h"
#import "LessonDelegate.h"
#interface Lesson : Activity
#property (retain, nonatomic) NSString *url;
#property (retain, nonatomic) SimpleManifest *manifest;
#property (retain, nonatomic, readonly) Activity *runningActivity;
#property (weak) id<LessonDelegate> delegate;
- (id) initWithUrl:(NSString*) aurl;
- (NSString*) deteails;
#end
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.
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
So I have one class CommentViewController.h in which I have
#import "FirstViewController.h"
#protocol CommentViewControllerDelegate;
#interface CommentViewController : UIViewController {
id <CommentViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <CommentViewControllerDelegate> delegate;
- (IBAction)submit:(id)sender;
-(IBAction)cancel:(id)sender;
#end
#protocol CommentViewControllerDelegate
-(void)commentViewControllerDidFinish:(CommentViewController *)controller;
#end
I synthesized delegate in the implementation
I try to access the protocol in FirstViewController.h:
#import "CommentViewController.h"
#interface FirstViewController : UIViewController <CommentViewControllerDelegate>
And in the implantation of FirstViewController :
- (void)commentViewControllerDidFinish:(CommentViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
}
The error appears on this line:
#interface FirstViewController : UIViewController <CommentViewControllerDelegate>
Error: Cannot find protocol declaration for 'CommentViewControllerDelegate'; did you mean 'UISplitViewControllerDelegate'?
Am I missing something? I always have trouble with protocols and delegates.
You have a loop in your include files.
Remove this line from CommentViewController.h:
#import "FirstViewController.h"
It's not referenced in that header file, and if it were, you could simply put:
#class FirstViewController;
instead of including the whole file.