I have the following in a project named testApp: (testAppViewController is the valid name of my view controller in the project)
PrevView.h
#import <UIKit/UIKit.h>
#import "testAppViewController.h"
#interface PrevView : UIView {
testAppViewController *viewController;
}
#property (nonatomic,retain) testAppViewController *viewController;
#end
When I build the project I'm getting the following error:
PrevView.h:13: error: expected specifier-qualifier-list before 'testAppViewController'
Am I missing something here? Any ideas?
Does "testAppViewController.h" import "PrevView.h"?
If so, you may want to delcare a forward class reference:
#class testAppViewController;
that replaces the import you have, and move the import into the .m file.
Usually when I see this type of error, it's a problem in the header file that you're trying to import. Check "testAppViewController.h"
Related
I have a very strange problem: "Can't find the type RCTResponseSenderBlock in scope." It's strange, because in one case it is there and in the other it doesn't, looks like a bug.
This is screenshot issue.
This my Objective-C file:
#import <Foundation/Foundation.h>
#import "React/RCTBridgeModule.h"
#import <React/RCTEventEmitter.h>
#import <React/RCTConvert.h>
#interface RCT_EXTERN_MODULE(BLEclass, NSObject)
RCT_EXTERN_METHOD(addEvent:(NSString *)name callback:(RCTResponseSenderBlock)callback )
#end
And this my Swift file, where i have issue :
import Foundation
#objc(BLEclass)
class BLEclass: NSObject{
#objc(addEvent:callback:)
func addEvent(_ name: String,_ callback:RCTResponseSenderBlock){
NSLog("%#", name);
let resultsDict = [
"name" : name
];
callback([NSNull(),resultsDict])
}
}
If you know how to fix it, please write answer.
Thanks.
I had this same issue and discovered I had to add the import to my main bridge file.
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
I out which file was set by looking at the Build settings under Swift Compiler - General -> Objective-C Bridging Header which appears to be the default for the app.
I have the following code:
#import <Foundation/Foundation.h>
#interface BBUtils : NSObject
{
}
-(CGPoint ) randomPoints;
#end
For some reason it complains on the randomPoints method saying Expected a Type? Why?
This could happen if CoreGraphics is not available. Then you'll need to link it explicitly:
Add proper import in your header to expose structs declared by CoreGraphics:
#import <CoreGraphics/CoreGraphics.h>
In my MyClass.h, I have this:
#import "AClass.h"
#interface MyInterface : UIViewController <UIScrollViewDelegate>
#property (strong, nonatomic) AClass *ptr;
#end
But when I compile it, I get an error saying Unknown type name 'AClass' , did you mean 'BClass'.
What I don't understand it I already have "#import "AClass.h", how can I fix my error?
In AClass.h, I have
#interface AClass : UICollectionViewFlowLayout
#end
And both AClass.h and MyClass.h are in the same directory.
Thank you.
(This answer is obsolete since the question was changed including the displayed code)
It's your headerfile, right? So don't import yourself.
In MyClass.m you need #import "MyClass.h", but not in the header file of MyClass itself.
Sorry, couldn't find a more appropriate title.
In My code I have two classes which should know of each others existence. So I use an instance variable which points to the other class. For that to work (I guess?) the other classes headers file should be imported so it knows which methods it has and such.
Here is my code (stripped down)
MainMenuController.h:
#import <Cocoa/Cocoa.h>
#import "IRCConnection.h"
#interface MainMenuController : NSViewController {
IRCConnection *ircConnection;
}
#property (strong) IRCConnection *ircConnection;
#end
IRCConnection.h:
#import <Foundation/Foundation.h>
#import "MainMenuController.h"
#interface IRCConnection : NSObject {
MainMenuController *mainMenuController;
}
#property (strong) MainMenuController *mainMenuController;
#end
As you can see they both import each other, but this creates an error (Unknown type name 'IRCConnection') in one, and in the other Unknown type name 'MainMenuController'.
However when the connection is just one way (e.g. only MainMenuController knows about IRCConnection) and thus there is only an import statement in one of the two, it works fine.
How can I have them to know about each other? In both ways.
Hope this question makes any sense.
you could remove the import from IRCConnection.h and use a #class statement instead.
like this:
#import <Foundation/Foundation.h>
#class MainMenuController;
#interface IRCConnection : NSObject {
then add a #import "MainMenuController.h" to IRCConnection.m
In the header, use forward declaration:
#class IRCConnection;
#interface MainMenuController : NSViewController {
IRCConnection *ircConnection; // ok
}
In the source file (.m), do #import.
You cannot have circular imports. You need to break them up, or introduce some forward declarations.
I make my first steps in objective-c and cocoa. I typed in the following example class, which compiles well in the iPhone main project. When I use the sample class in an OCUnitTest, the compiler raise an error.
class:
#import <UIKit/UIKit.h>
#interface ProjekteTableViewController : UITableViewController {
NSFetchedResultsController *fetchedResultsController;
}
#property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
#end
Now the question: I see in UIKit.h no direct or indirect #import for the NSFetchedResultsController.h file.
How does the compiler resolve this identifier (NSFetchedResultsController) ?
I expected the compiler error not only in the UnitTest project, but also in the main project.
I suspect you've got a prefix header that's including CoreData.