Any help on correct syntax in Swift to access a “typedef void PaStream;” from a C file?

拜拜、爱过 提交于 2019-12-11 03:39:12

问题


I have compiled and imported a dylib C Library called portaudio (PortAudio website) into an Xcode 6.1 Swift project, all the functions / types are accessible except for one which is

typedef void PaStream;

I am having trouble understanding how to use that in Swift, in C I declare it like:

PaStream *audioStream = NULL;

Can anybody help on the Swift equivalent as I get a warning saying undeclared Type / unresolved identifier, it looks like Swift can not bridge a typedef void xyz; ?

Many thanks for any help.


回答1:


The C typedef

typedef void PaStream;

is indeed not imported to Swift because you can't define a variable of type void. Even in C, you would only define pointer variables of type PaStream *.

Therefore you could add

typedef PaStream *PaStreamPtr;

to the bridging header file and then use it as

var audioStream : PaStreamPtr = nil


来源:https://stackoverflow.com/questions/27886861/any-help-on-correct-syntax-in-swift-to-access-a-typedef-void-pastream-from-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!