Unknown type name while known? - ios

Xcode has showed out of the blue this error: "Unknown type name"
I'll explain:
My StoriesViewController.h:
#import <UIKit/UIKit.h>
#import "Stories.h"
#interface StoriesViewController : UIViewController <UITextViewDelegate>
#property (strong) Stories *story; //Here it goes- "Unknown type name `Stories`"
#property (weak) IBOutlet UITextView *storyView;
#end
In my Stories.h:
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface Stories : UIDocument
#property (strong) NSString * storyContent;
#end
Again, out of the blue.
Thanks in advance.
EDIT:
In my ViewController.h:
#import <UIKit/UIKit.h>
#import "Stories.h"
#import "StoriesViewController.h"
#import "StoriesPickerViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface ViewController : UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
}
#end
NB #class throws loads of ARC issues.
I have removed useless references to ViewController.h, worked.
SOLVED!

You have a circular reference problem.
What's happening is that when you load your ViewController it goes through it's imports, it loads Stories.h, it goes to load it's imports and it goes back to ViewController.h, so you are stuck in an infinite loop there.
Either remove one of the conflicting imports, or use forward class declaration (that example is for C++, see here for an example with Objective-C)

Related

Problems with adding a new delegate to a new controller

I am trying to figure out how to take the delegate in LocationViewController and SetScoringTableViewController and implement both of them in GameDetailsTableViewController. LocationViewControllerDelegate was already working, but when I added the new SetScoringTableViewController, the program had an error.
LocationViewController.h
#import "ViewController.h"
#class LocationViewController;
#protocol LocationViewControllerDelegate <NSObject>
- (void)addItemViewController:(LocationViewController *)controller didFinishEnteringItem:(NSString *)name;
#end
#interface LocationViewController : UIViewController
#property (nonatomic, weak) id <LocationViewControllerDelegate> delegate;
#end
SetScoringTableViewController.h
#import <UIKit/UIKit.h>
#import "GameDetailsTableViewController.h"
#import "LocationViewController.h"
#class SetScoringTableViewController;
#protocol SetScoringTableViewControllerDelegate <NSObject>
- (void)addItemViewControllerSS:(SetScoringTableViewController *)SScontroller didFinishEnteringItemSS:(NSString *)SSname;
#end
#interface SetScoringTableViewController : UITableViewController
#property (nonatomic, strong) id <SetScoringTableViewControllerDelegate> SSdelegate;
#end
GameDetailsTableViewController.h
#import <UIKit/UIKit.h>
#import "LocationViewController.h"
#import "SetScoringTableViewController.h"
#interface MainViewController : UITableViewController <LocationViewControllerDelegate, SetScoringTableViewControllerDelegate>
When I run this I get an error: "Cannot find protocol declaration for 'SetScoringTableViewControllerDelegate' even though I have.
The only way I have found to fix this problem is to put the "SetScoringTableViewController delegate in the LocationView Controller, but I know that is not right. Any help would be greatly appreciated.
You have a dependency loop:
SetScoringTableViewController.h
#import "GameDetailsTableViewController.h"
GameDetailsTableViewController.h
#import "SetScoringTableViewController.h"
But it looks like you can remove the #import "GameDetailsTableViewController.h" as there is no mention of it in the header file.
What you're experiencing is an an #import cycle. To break the import loop
remove this import line:
#import "GameDetailsTableViewController.h"
from SetScoringTableViewController.h and put it in a .m file.
Try to separate the delegate on a different .h file.

Duplicate interface definition for class "ViewController"

At the last line, I got the error: Duplicate interface definition for class "ViewController". I want to do an IBAction. What is the fault? What can I do? Please help me.
//
// ViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate>
- (IBAction)showEmail:(id)sender;
#end
#interface ViewController : UIViewController <MFMessageComposeViewControllerDelegate> {
}
-(IBAction)sendMessage:(id)sender;
- (IBAction)showEmail:(id)sender;
#property (nonatomic, strong) IBOutlet UIWebView *site ;
- (IBAction)call:(id)sender;
#property (retain, nonatomic) IBOutlet UIButton *myBotton;
#end
#interface ViewController : UIViewController**i**
The problem is exactly what the error states. You defined #interface viewController twice. Change the name of one to something else. As a side note, it is a terrible idea to name something with a name apple has already used. You should change both viewControllers to something else, more descriptive of what it does, like mailViewController or setupViewController. Weird stuff can happen when you use apple defined names.
#interface FSMainiPadViewController : UIViewController
Why don't you just make it simple like this?
// ViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#interface ViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>
// Actions
- (IBAction)showEmail:(id)sender;
- (IBAction)sendMessage:(id)sender;
- (IBAction)call:(id)sender;
// Properties
#property (nonatomic, strong) IBOutlet UIWebView *site;
#property (retain, nonatomic) IBOutlet UIButton *myBotton;
#end

Declaring a property

I am trying to declare a property
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController
{
#property (nonatomic, strong) MPMoviePlayerController*player;
}
#end
I receive a red warning sign when i click on it, it reads;
a parameter list without types is only allowed in function definition
properties are outside of braces
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController
{
// here is for ivars only
id _something;
}
// properties and methods
#property (nonatomic, strong) MPMoviePlayerController*player;
#end

Cannot find protocol declaration for 'MFMailComposeViewControllerDelegate'; did you mean 'UIPageViewControllerDelegate'?

This code :
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MessageUI/MessageUI.h>
#import "MessageComposerViewController.h"
#import <MessageUI/MFMailComposeViewController.h>
#interface MapViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate
- (IBAction)showEmail:(id)sender;
{
IBOutlet MKMapView *mapView;
}
#property (nonatomic, retain) MKMapView *mapView;
#end
This problem or error :
Cannot find protocol declaration for 'MFMailComposeViewControllerDelegate'; did you mean 'UIPageViewControllerDelegate'?
for this lign : #import "MessageComposerViewController.h"
Expected identifier or '('
for this lign : #interface MapViewController : UIViewController // Add the delegate
and this lign : {
Thanks for advance. :)
Try This,
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MessageUI/MessageUI.h>
#import "MessageComposerViewController.h"
#import <MessageUI/MFMailComposeViewController.h>
#interface MapViewController : UIViewController <MFMailComposeViewControllerDelegate,UINavigationControllerDelegate> {
IBOutlet MKMapView *mapView;
}
- (IBAction)showEmail:(id)sender;
#property (nonatomic, retain) MKMapView *mapView;
#end
If you do the above and still see the warning in Xcode, try building or building & running your app. Sometimes these warnings linger after you've addressed the problem and are cleared out by a compilation cycle.
I encountered the same problem today coding an app for ios8.
First thing that I did was re-add the framework, but it didn't help. The problem was I ignored libAWDProtobufFacetimeiMessage - a protocol buffer file. I'm no professional to guess why, but when I added both buffer and the framework itself, the error message disappeared. I have posted a screenshot here. Hope my answer helps anyone looking here in the future.

Error: Expected specifier-qualifier-list before XXX

it did it so many times and i didn't had any problems with it, but this time i still getting the error above, my relevant code is this:
#import "PiecesChoisies.h"
#interface SelectionMobilier : UIViewController {
IBOutlet PiecesChoisies *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies
}
#end
Thanx in advance for any suggestions :)
EDIT :
I try this :
#import "PiecesChoisies.h"
#interface SelectionMobilier : UIViewController {
IBOutlet NSString *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies
}
#end
Now i got this stack:
PiecesChoisies is not recognized as a type. This may happen because it has cyclical dependencies.
The following code example illustrates the problem. Classes A and B create a circular dependency trying to import each other.
#import "B.h" // <-- A imports B
#interface A : NSObject
#end
#import "A.h"
#implementation A
#end
#import "A.h" // <-- and B imports A
#interface B : NSObject
#end
#import "B.h"
#implementation B
#end
Because the classes are never created, the compiler treats them as unknown tokens, so the error shows as Expected specifier-qualifier-list before XXX. In other words "I expected something meaningful before XXX".
To remove the circular dependency:
And add a forward class declaration (#class) on the interface file.
Move the #import from the interface to the implementation file.
The class declaration tells the compiler "don't worry, I'll define this later", so the header becomes safe to import because the conflicting definition is now out of sight on the implementation file.
Here is the result for the previous example:
#class B; // <---- #import "B.h" replaced with #class B
#interface A : NSObject
#end
#import "A.h"
#import "B.h" // <---- #import "B.h" added
#implementation A
#end
And do the same with class B:
#class A; // <---- #import "A.h" replaced with #class A
#interface B : NSObject
#end
#import "B.h"
#import "A.h" // <---- #import "A.h" added
#implementation B
#end
The problem will be located in PiecesChoisies.h. Change:
IBOutlet PiecesChoisies *piecesChoisies;
to
IBOutlet NSString *piecesChoisies;
that will confirm that the problem is located in the .h file.
If this is in a header file, use
#class PiecesChoisies;
Instead of the import statement. Import the .h file in your .m file.

Resources