Error: Expected specifier-qualifier-list before XXX - ios

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.

Related

Why do I get Method definition for ... not found error after refactoring?

I have a very small class with an enum in the .h file, and that's it. I recently refactored the name of the .h file and for some reason the .m file names didn't refactor, so I had to change it manually. Now everything works as intended, but I suddenly get a warning on my #implementation in my .m file: Method definition for ... not found. Not sure why.
It looks like this in .m:
#import "TabTypeEnum.h"
#interface TabTypeEnum ()
#end
#implementation TabTypeEnum
- (void)viewDidLoad {
[super viewDidLoad];
}
#end
and in the .h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
#interface TabTypeEnum : UIViewController
typedef enum {
MyTravels = 0,
Excursions,
Experiences,
Map,
Discover
} MyTabType;
- (void)myTabFunc: (MyTabType) myTab;
#end
NS_ASSUME_NONNULL_END
I didn't get the warning before, and all I did was change all the names to TabTypeEnum. I don't want to have the method implemented in the .m file. It's fine as it is.

Unknown type name 'NSString' when I define a block

When I define my block in my .h file, there comes an issue:
Unknown type name NSString
My code is below:
typedef void(^CancelBlock)();
typedef void(^ConfirmBlck)(NSString *); // this line comes the error
#import <UIKit/UIKit.h>
#interface LMLUpspringView : UIView
#property (nonatomic, copy) CancelBlock cancelBlock;
#property (nonatomic, copy) ConfirmBlck confirmBlock;
#end
But, why is my first block ok and the second report's an error?
You define block above the #import <UIKit/UIKit.h> (in the .h file), so there did not import the NSString, you should cut the #import <UIKit/UIKit.h> above the block define.
you need to declare block as below
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
typedef void(^ConfirmBlck)(NSString * string);
In latest versions of xcode you can simply specify
#import <Foundation/NSString.h>
any NS Foundation class can be imported as needed.
position declaration uikit import then follow:
// declare
#property(nonatomic,strong)void(^ConfirmBlck)(NSString * string);
// define
[self setConfirmBlck:^(NSString *indexpVal) { }];
// call
if (self.ConfirmBlck) {
self.ConfirmBlck(selectedVal);
}

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.

Forward declaration issue - ARC refactor

I am running an ARC 'refactor' on an old iOS app.
However, I am getting the following error
Receiver type 'WarningCallback' for instance message is a forward declaration
WarningCallback.h
#class WarningCallback;
#import <UIKit/UIKit.h>
#import "WebViewController.h"
#import "Constants.h"
#protocol WarningCallback
-(void) warningDismissedAndNavigateToCall:(BOOL) navigateToCall;
#end
#interface WarningViewController : WebViewController {
}
#property (nonatomic,retain) WarningCallback* parentVC;
#end
WarningCallback.m
#import "WarningViewController.h"
#implementation WarningViewController
#synthesize parentVC;
...
-(IBAction) done:(id) sender {
[[self parentVC] warningDismissedAndNavigateToCall:NO];
}
#end
The error occurs on the following line of WarningCallback.m
[[self parentVC] warningDismissedAndNavigateToCall:NO];
The error is because of the line #class WarningCallback;. The error message means that the compiler found a forward declaration of WarningCallback, but is not able to find the corresponding implementation. That's because WarningCallback is not a class, but a protocol.
If you want to forward declare a protocol you can do so as follows:
#protocol WarningCallback;
#interface WarningViewController : WebViewController
#property (nonatomic, weak) id<WarningCallback> parentVC;
#end
#protocol WarningCallback
- (void)warningDismissedAndNavigateToCall:(BOOL) navigateToCall;
#end
Note how I've declared parentVC.
Remove the line:
#class WarningCallback;
When declaring a #protocol, it is not necessary to also declare it as a #class unless you have a specific reason to do so. See:
What's with the declare a class and declare a protocol with the same name?

Unknown type name while known?

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)

Resources