Ram*_*sel 8 typedef objective-c swift
我有一个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;
Run Code Online (Sandbox Code Playgroud)
我已将此文件包含在桥接头中.但是,当我尝试访问VMVideoCategoryTypeSwift文件时,我收到一个错误:
Use of undeclared type 'VMVideoCategoryType'
有没有办法让这项工作或我必须在Swift中完全重新定义这种类型?
Mar*_*n R 11
我有点推测,但原因似乎是Objective-C对象NSString不能静态分配(参见例如在Objective-C中的对象是否曾在堆栈上创建过?).如果
typedef NSString VMVideoCategoryType;
Run Code Online (Sandbox Code Playgroud)
导入到Swift然后你可以声明一个局部变量
var foo : VMVideoCategoryType
Run Code Online (Sandbox Code Playgroud)
这将是一个NSString而不是指针NSString.
另请注意,您在Swift中看到的内容NSString与NSString *
Objective-C中的内容相对应.
如果定义VMVideoCategoryType为一个typedef的NSString *
则是在斯威夫特可见:
typedef NSString * VMVideoCategoryType;
extern VMVideoCategoryType const VMVideoCategoryType_MusicVideo;
// ...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1689 次 |
| 最近记录: |