如何解决无法通过桥接头将名为“Category”的 Objective-C 接口导入 swift
下面的 swift 代码抛出这个错误('Category' 在这个上下文中的类型查找是不明确的)
// ctx is the UIContext,fetchCategories is an Obj-C function that queries CoreData
//for the Categories,the cast shouldn't even be necessary but swift will not
//recognize my obj-c interface
if let cats = self.fetchCategories(ctx) {
let array = cats as! [Category] //error happens on this line
return array
}
这是我的桥接头中的实现, 还有许多其他导入,但我在这篇文章中删除了它们,所以请注意,它是近 40 个其他 .h 文件的全功能桥接头
#ifndef AppDaTaroom_Bridging_Header_h
#define AppDaTaroom_Bridging_Header_h
#import "Category.h"
#endif /* AppDaTaroom_Bridging_Header_h */
下面是接口实现
@interface Category : _Category <QLPreviewItem> {
UIImage *squareThumb;
}
我意识到更改 Category 类的名称将是最好的选择,因为这可能是由于命名约定很常见,但是当我将代码更改为:
if let cats = self.fetchCategories(ctx) {
let array = cats as! [<ModuleName>.Category] //error happens on this line
return array
}
仍然说查找太模糊。除了更改界面名称之外,我还可以尝试关于其他事情的任何想法,因为这确实不是一个选择,我会为您提供所有原因。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。