objective-c - XCode 7.3 破坏了 Bridging-Header.h?

标签 objective-c xcode swift bridging-header

我刚刚升级到 XCode 7.3,它似乎破坏了我的 PROJECT_NAME-Bridging-Header.h

我收到这个错误: enter image description here

BBCategoryType 是一个在名为 BBCategory.h 的文件中定义的枚举,该文件在我的 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"

我还注意到,如果我删除 PROJECT_NAME-Bridging-Header.h,我会收到相同的错误 - 如果我将它添加回项目,我会收到相同的错误 - 就好像 XCode 7.3 甚至无法识别PROJECT_NAME-Bridging-Header.h 了。我已验证在我的build设置中也正确引用了桥接 header 。我已按照此处的所有说明进行操作以确保正确设置:

How to call Objective-C code from Swift

这是 BBCategory.h 的内容,它没有改变并且在升级到 XCode 7.3 之前完全正常工作,这肯定是问题开始的时候:

#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
};

这可能是 XCode 7.3 的一些错误,还是我需要进行一些更改才能使其正常工作?

我还注意到桥接头在下面以红色显示: enter image description here

这让我觉得 XCode 7.3 无法识别桥接 header 。一切都与 XCode 7.1、7.2 一起工作 - 7.3 就坏了

最佳答案

问题是你的枚举是在你的@interface内部定义的

虽然这在 Objective-C 中是有效的,但它似乎对 Swift 隐藏了它(我不确定这是否有意为之 - 绝对想知道是否还有其他人对此有更多了解)。

因此,您可以通过将枚举移到@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

...

关于objective-c - XCode 7.3 破坏了 Bridging-Header.h?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36461494/

相关文章:

objective-c - 无法将 UITableView 滚动到底部

iphone - 如何将文件从 URL 复制到文档文件夹?

xcode - Safari 扩展无效代码签名标识符

ios - 将 Objective-C 桥接到 Swift - 看不到文件

ios - 自定义 UIAlertView : How to prevent an Objective-C object to be released automatically by ARC or How to retain an object manually in an ARC environment

ios - UITextField TableView 单元格 - iOS

swift - 使用 Swift 以编程方式设置 UINavigationController 的 UINavigationBar

swift - 如何实现上下文可控的 Swift Codable Encode 函数?

iphone - Interface Builder 中的 UIView 构建连接到我的自定义 UIViewController

objective-c - 解决 Cocoa 中的 EXC_BAD_ACCESS 问题?