我有一个 typedef 如下:
typedef NSString VMVideoCategoryType;
extern VMVideoCategoryType *const VMVideoCategoryType_MusicVideo;
extern VMVideoCategoryType *const VMVideoCategoryType_Audio;
extern VMVideoCategoryType *const VMVideoCategoryType_Performance;
extern VMVideoCategoryType *const VMVideoCategoryType_Lyric;
extern VMVideoCategoryType *const VMVideoCategoryType_Show;
我已将此文件包含在桥接标头中。但是,当我尝试访问时VMVideoCategoryType
在 Swift 文件中我收到一个错误:
Use of undeclared type 'VMVideoCategoryType'
有什么办法可以让这个工作或者我必须在 Swift 中完全重新定义这个类型吗?
我有点猜测,但原因似乎是 Objective-C
像这样的物体NSString
不能静态分配(参见例如Objective-C 中的对象是否在堆栈上创建? https://stackoverflow.com/questions/20663388/are-objects-in-objective-c-ever-created-on-the-stack). If
typedef NSString VMVideoCategoryType;
导入到 Swift 然后你可以声明一个局部变量
var foo : VMVideoCategoryType
这将是一个NSString
and not一个指向NSString
.
另请注意,您在 Swift 中看到的内容为NSString
对应于NSString *
在 Objective-C 中。
如果你定义VMVideoCategoryType
作为类型定义NSString *
然后它is在 Swift 中可见:
typedef NSString * VMVideoCategoryType;
extern VMVideoCategoryType const VMVideoCategoryType_MusicVideo;
// ...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)