Cannot find interface declaration for 'UIView' in iOS Swift Project - swift

I have a swift project which I'm making use of MBProgressHUD in through a Bridging header file. The issue I'm having is that UIView doesn't appear to be recognised as type and I don't know why.
In my bridging header I have:
#import "MBProgressHUD.h"
The errors I get when I try to build are all along the same lines:
Cannot find interface declaration for 'UIView', superclass of MBProgressHUD.
I have checked the MBProgressHUD file and I can see that it definitely imports the following:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import "MBProgressHUD.h"
#import "CSNotificationView.h"
Has anyone else seen a similar issue? If so do you know what the issue is and how can I fix it?

I also come across the same issue and thats what i did to use MBProgressHud with swift 2
1) Specify use_frameworks! in your Podfile to use frameworks.
2) Add #import in your bridging header, use angle brackets instead of double quotes e.g -
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import <MBProgressHUD/MBProgressHUD.h>
3) in your swift file also import MBProgressHUD e.g.
import UIKit
import MBProgressHUD
Now you can use MBProgressHud like -
MBProgressHUD.showHUDAddedTo(self.view, animated: true);
Hope it will help.

Remove your existing bridging header file and add a new one.
Make sure you are adding your bridging header path in SWIFT_OBJC_BRIDGING_HEADER under the target section instead of the project section.

You could also try adding a precompiled prefix header file (.pch) to your project. You'll find it under File/New/Other, there add the #import <UIKit/UIKit.h>clause, and then in the target's build settings, under Apple LLVM 7.0 - Language, set the Precompile Prefix Header flag to yes and add the .pch file like this "YourProjectName/YourProject-Prefix.pch".
See also this answer.

If you include the MBProgressHUD library with CocoaPods try to include a line similar to this
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import "MBProgressHUD.h"
in
BridgeHeader.h and in Objective-C Bridging Header key in Build Settings choose the header.
For test if the library is correctly added I try to show a progress with this instruction in the ViewController:
MBProgressHUD.showHUDAddedTo(self.view, animated: true);
I tried it in a new project and it works.

Related

error: expected specifier-qualifier-list before 'cv'

I am using OpenCV framework for image processing, i am identifying edge in photo for
normal iOS project, now i am converting this code in cocos2d project, i have imported all
required headers but while compiling i am getting this error:expected specifier-qualifier-list before 'cv'. here is my code
#import "cocos2d.h"
#import "CameraController.h"
#import "Globals.h"
#interface BotoxEffectController : CCLayer
{ cv::VideoCapture *_videoCapture; cv::Mat _lastFrame;}//this is line where i am
getting error
#property (nonatomic, retain) CCSprite *sprite2D;
+(CCScene *) scene;
#end
here is code in .pch file.
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __cplusplus
#import <OpenCV/opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Please refer below screen shot BotoxEffectController class interface where error is & implementation file has extension .mm.
here is .pch file where i am importing opencv.hpp
I think I know what's going on here. Try adding the OpenCV header to your BotoxEffectController header file:
#import <OpenCV/opencv2/opencv.hpp>
If this fixes the compile errors, the problem is with the prefix.pch. For some reason it doesn't parse the #if __cplusplus part. You can verify it by adding a warning to it, see if it triggers:
#ifdef __cplusplus
#warning "ok so it DID import the OpenCV header"
#import <OpenCV/opencv2/opencv.hpp>
#endif
If that is the issue, I can't tell you why the opencv header in the prefix.pch won't work. I only remember having had this issue once or twice before, but can't remember how I fixed it. One thing you should check: the BotoxEffectController.h should have its File Type set to "Default - C Header" and not C++ header.

IOS: #import <AddressBook/AddressBookUI.h> file not found

I have included both frameworks and import header files. But xCode throws an error because of the missing AddressBookUI.h file.
#import "PersonViewController.h"
#import <AddressBook/AddressBook.h>
#import <AddressBook/AddressBookUI.h>
#interface PersonViewController () <UITextFieldDelegate, UIActionSheetDelegate>
{
}
Any advice?
AddressBookUI.h is in the AddressBookUI framework, not the AddressBook framework.
#import <AddressBookUI/AddressBookUI.h>
In your project explorer, select your project, then go to target>build phases>link binary with libraries and then add the library to your project, after that the import will work.

Xcode: very strange error subclassing my own class

I have an iPhone app with a custom class, Detail, a subclass of UIViewController that I created.
I need to make a subclass of Detail, and I want to to call it ActivityDetail. So I wrote the following in my ActivityDetail.h file:
#import <UIKit/UIKit.h>
#import "Detail.h"
#interface ActivityDetail : Detail {
}
#end
The problem is that I'm getting a compiler error telling me this:
error: cannot find interface
declaration for 'Detail', superclass
of 'ActivityDetail'
And the strange thing is: I can change the superclass from Detail to UIView (for example), compile getting many errors (obviously), and then change the superclass to Detail again and everything works fine! But if I then change anything to the Detail class the problem comes back from the beginning...
How can I solve this?
It is recommended to not import classes beyond the default Foundation or UIKit imports in your header files. Instead you should do something similar:
Header
#import <UIKit/UIKit.h>
#class Detail;
#interface ActivityDetail : Detail {
}
#end
Implementation
#import "ActivityDetail.h"
#import "Detail.h"
#implementation ActivityDetail
#end
This allows your header to "know" about additional classes without forcing all "importers" of that header to also import everything it imports.
Here is a great reference question, and a great answer, regarding the usage of #class and #import.
Erm you are importing Detail as Dettaglio.h. Probably the compiler is not fluent in Italian.
Are you importing the .h where Detail is declared?
#import "Detail.h"
Either #import "Detail.h" or subclass from Dettaglio (depends on whichever one your Detail class is actually named.

Adding Existing Framework to Xcode (iPhone) error

I have added the <QuartzCore/QuartzCore.h> to my Frameworks folder in my iPhone project and added the #import "<QuartzCore/QuartzCore.h>" statement at the top of a custom UIView class.
However the custom UIView class gives me a "No such file or directory" compliation error in relation to the <QuartzCore/QuartzCore.h> framework. Is there something else I need to set so that the compiler can see the framework.
I'm not expert on the Xcode IDE so any assistance would be extremely welcome.
try removing the quotes around the <QuartzCore/QuartzCore.h>
you don't need them when you are importing a framework.
This is the correct syntax:
#import <QuartzCore/QuartzCore.h> // not #import "<QuartzCore/QuartzCore.h>"

Why do I get this error "error: expected specifier-qualifier-list before 'NSManagedObjectContext'?

1) I have the CoreData.framework imported. In Groups & Files I see it in the Framworks list together with UIKit.framework, Foundation.framework, CoreGraphics.framework.
2) I have this code, which should actually work. Don't know what that error means...
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface RootViewController : UITableViewController <CLLocationManagerDelegate> {
NSMutableArray *dataArray;
NSManagedObjectContext *managedObjectContext; // HERE's THE ERROR LINE
}
Edit: After importing CoreData, the error disappeared. BUT: Actually UIKit contains it, or not??
#import <CoreData/CoreData.h>
I have an Apple example code and they NEVER import CoreData, and it works.
Apple is taking advantage of the precompiled header (.pch file). Your projects do too when you start with a template and check the "Use Core Data for storage" option.
Also, you can use the precompiled header file to add any header files you wish to import for all source files in your target and project.
You need to link the CoreData framework and import CoreData/CoreData.h in the header file. UIKit does not contain the Core Data framework.