有没有办法将Swift结构的地址强制转换为void UnsafeMutablePointer?
我尝试了这个没有成功:
struct TheStruct {
var a:Int = 0
}
var myStruct = TheStruct()
var address = UnsafeMutablePointer<Void>(&myStruct)
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:
我实际上尝试移植到Swift 的上下文是Learning CoreAudio中的第一个示例.
这是我到目前为止所做的事情:
func myAQInputCallback(inUserData:UnsafeMutablePointer<Void>,
inQueue:AudioQueueRef,
inBuffer:AudioQueueBufferRef,
inStartTime:UnsafePointer<AudioTimeStamp>,
inNumPackets:UInt32,
inPacketDesc:UnsafePointer<AudioStreamPacketDescription>)
{ }
struct MyRecorder {
var recordFile: AudioFileID = AudioFileID()
var recordPacket: Int64 = 0
var running: Boolean = 0
}
var queue:AudioQueueRef = AudioQueueRef()
AudioQueueNewInput(&asbd,
myAQInputCallback,
&recorder, // <- this is where I *think* a void pointer is demanded
nil,
nil,
UInt32(0),
&queue)
Run Code Online (Sandbox Code Playgroud)
我正在努力留在Swift,但如果事实证明这是一个问题而不是一个优势,我将最终链接到一个C函数. …
我应该如何从Swift文件中调用C++函数(不涉及类)?我试过这个:
在someCFunction.c中:
void someCFunction() {
printf("Inside the C function\n");
}
void aWrapper() {
someCplusplusFunction();
}
Run Code Online (Sandbox Code Playgroud)
在someCpluplusfunction.cpp中:
void someCplusplusFunction() {
printf("Inside the C++ function");
}
Run Code Online (Sandbox Code Playgroud)
在main.swift中:
someCFunction();
aWrapper();
Run Code Online (Sandbox Code Playgroud)
在Bridging-Header.h中:
#import "someCFunction.h"
#import "someCplusplusFunction.h"
Run Code Online (Sandbox Code Playgroud)
我发现这个答案非常有用,但我仍然无法使其发挥作用.你能指出我正确的方向吗?
谢谢!