在Swift中使用obj-c typedef

拉姆塞尔

我有一个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;

我已经将此文件包含在桥接头文件中。但是,当我尝试访问VMVideoCategoryTypeSwift文件时,出现错误:

Use of undeclared type 'VMVideoCategoryType'

有什么办法可以使这项工作,还是我必须在Swift中完全重新定义此类型?

马丁·R

我有点推测,但是原因似乎是NSString不能静态分配像Objective-C这样的对象(请参阅例如,是否在堆栈上创建了Objective-C中的对象?)。如果

typedef NSString VMVideoCategoryType;

被导入到Swift中,然后您可以声明一个局部变量

var foo : VMVideoCategoryType

这将是,NSString不是的指针NSString

还要注意,您在Swift中看到的NSString对应NSString *于Objective-C。

如果定义VMVideoCategoryType为一个typedef的NSString *在斯威夫特可见:

typedef NSString * VMVideoCategoryType;

extern VMVideoCategoryType const VMVideoCategoryType_MusicVideo;
// ...

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章