3

I just upgraded to XCode 7.3 and it seems to have broken my PROJECT_NAME-Bridging-Header.h

I am receiving this error: enter image description here

BBCategoryType is an enum defined inside a file called BBCategory.h, and that file is imported within my PROJECT_NAME-Bridging-Header.h:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "BBCategory.h"

I also noticed that if I remove the PROJECT_NAME-Bridging-Header.h, I receive the same error - and if I add it back to the project I receive the same error - as if XCode 7.3 doesn't even recognize the PROJECT_NAME-Bridging-Header.h anymore. I have verified that the bridging header is correctly referenced in my build setting as well. I have followed all the instructions here to ensure that it is properly set up:

How to call Objective-C code from Swift

Here is content of BBCategory.h which has not changed and was completely working prior to upgrade to XCode 7.3 which is certainly when the problem started:

#import "PCFCategory.h"

/**
 *  Category class that is a subclass of PCFCategory.
 */
@interface BBCategory : PCFCategory

/**
 *  Enum that describes the type of Category, used in BBSubMenuViewController and PCFCategoryMap+BBAdditions.
 */
typedef NS_ENUM(NSUInteger, BBCategoryType) {
    /// BBCategoryTypeFeatured for Featured Category.
    BBCategoryTypeFeatured,
    /// BBCategoryTypeNormal for Normal Category.
    BBCategoryTypeNormal,
    /// BBCategoryTypeHome for Home Category.
    BBCategoryTypeHome,
    /// BBCategoryTypeError if the category type is unknown
    BBCategoryTypeError
};

Could this be some bug with XCode 7.3 or do I need to make some change for it to work?

I have also noticed that the bridging header is appearing in red below: enter image description here

which makes me think that XCode 7.3 cannot recognize the bridging header. Everything was working with XCode 7.1, 7.2 - with 7.3 this broke

Community
  • 1
  • 1
etayluz
  • 15,920
  • 23
  • 106
  • 151
  • 1
    "Could this be some bug with XCode 7.3" No, it couldn't. But there is a bug in your question: you are not giving enough information. Show the Objective-C declaration of BBCategoryType, so that others can reproduce this, please. Thanks. – matt Apr 06 '16 at 20:40
  • 2
    Please upload contents of `BBCategory.h` and the swift file that caused the error. This could be an error in the declaration of `BBCategoryType` because there are many different ways to declare `enum`s in Objective-C. – Coder-256 Apr 06 '16 at 20:41
  • I have added the content of BBCategory.h - it has not changed in months - but please see my new comment about the the bridging header in red – etayluz Apr 06 '16 at 20:52
  • 2
    The red highlighting of the file name indicates that Xcode can no longer find the bridging header file. Locate it in Finder, and drag it into your project to re-link it. Also check that it is selected in your target's Build Settings > Objective-C Bridging Header. – Hamish Apr 06 '16 at 21:01
  • I have manually removed and added the bridging-header.h and that looks fine. I also commented out the BBCategoryType code and it compiles - so I'm tempted to believe that @Coder256 is correct that BBCategoryType is not declared in a way that Swift in XCode 7.3 can digest it – etayluz Apr 06 '16 at 21:06
  • Have you tried making sure that all files (the Objective-C file, the bridging header, and the swift file) all are part of the target that you are currently trying to build and that that target is selected at the top of the Xcode window? – Coder-256 Apr 06 '16 at 21:22

1 Answers1

4

The problem is your enum is defined inside your @interface

Although this is valid in Objective-C, it appears to conceal it from Swift (I'm not sure if this is intended or not - would definitely like to know if anyone else knows more about this).

You can therefore fix it by moving the enum outside the @interface.

#import "PCFCategory.h"

/**
 *  Enum that describes the type of Category, used in BBSubMenuViewController and PCFCategoryMap+BBAdditions.
 */
typedef NS_ENUM(NSUInteger, BBCategoryType) {
    /// BBCategoryTypeFeatured for Featured Category.
    BBCategoryTypeFeatured,
    /// BBCategoryTypeNormal for Normal Category.
    BBCategoryTypeNormal,
    /// BBCategoryTypeHome for Home Category.
    BBCategoryTypeHome,
    /// BBCategoryTypeError if the category type is unknown
    BBCategoryTypeError
};

/**
 *  Category class that is a subclass of PCFCategory.
 */
@interface BBCategory : PCFCategory

...
Hamish
  • 78,605
  • 19
  • 187
  • 280