3

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?

  • Could you share the relevant part of your project to github? This is probably project settings related or a typo somewhere. – Sulthan Sep 20 '15 at 18:04
  • did you install MBProgressHUD via CocoaPods? or downloaded manually? – Bartłomiej Semańczyk Sep 22 '15 at 19:17
  • I downloaded it manually and included it in the project. I should add that this used to work without any problems before I updated the project for iOS 9 as Xcode suggested. –  Sep 23 '15 at 20:22

4 Answers4

8

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.

Viper
  • 1,408
  • 9
  • 13
  • Thanks for the suggestion - the original error has gone away however I now see an error `'MBProgressHUD/MBProgressHUD.h' file not found` which shows up on the import for MBProgressHUD in the bridging header file. Do you have any idea why? –  Sep 25 '15 at 20:16
  • Please use angle brackets while importing in bridging header file e.g #import – Viper Sep 26 '15 at 04:57
  • Yes I am using angle brackets in the header file (I precisely followed your steps). I'm still not sure why I get the file not found error though. Have you ever come across this issue before? –  Sep 27 '15 at 15:52
  • Hey make sure you are not creating two bridging header file.. i know it sounds silly but that can be a case.. – Viper Sep 27 '15 at 17:16
3

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.

Nishant
  • 12,529
  • 9
  • 59
  • 94
  • Thanks - Just tried your suggestion for deleting and re-adding the file, however I still seem to get the same error message. I also double checked that the filepath exists and the bridging header is actually in the same place (which it is). –  Sep 18 '15 at 14:53
1

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.

ciccioska
  • 1,291
  • 16
  • 22
  • Thanks for the suggestion - I tried this too, however it didn't help. I've updated my question slightly to reflect it. –  Sep 22 '15 at 19:16
  • As described in my modified answer, check if it help you. – ciccioska Sep 23 '15 at 09:40
1

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.

Community
  • 1
  • 1
peacer212
  • 935
  • 9
  • 15