我正在尝试使用快速代码处理MIDI会话,并且遇到了一些代理问题。
这是 Objective-C 中的一个工作示例。
OSStatus status = MIDIClientCreate(CFSTR("MIDI Client"), MIDIStateChangedHandler, nil, &client);
void MIDIStateChangedHandler(const MIDINotification *message, void *refCon)
{
NSLog(@"MIDIStateChanged!");
}
这就是我正在尝试使用 Swift :
var status = MIDIClientCreate("the client", notifyProc: MIDIStateChangedHandler, notifyRefCon: nil, outClient: client)
func MIDIStateChangedHandler(message: MIDINotification, refCon: UnsafeMutablePointer<Void>)
{
println("MIDIStateChanged!");
}
这是我无法弄清楚的错误(我是具有多年C#经验的iOS新手):
无法转换表达式的类型'(StringLiteralConvertible,notifyProc:(MIDINotification,refCon:UnsafeMutablePointer) - &gt;(),notifyRefCon:NilLiteralConvertible,outClient:@lvalue MIDIClientRef!)'来键入'StringLiteralConvertible'
var status = MIDIClientCreate("the client", notifyProc: MIDIStateChangedHandler, notifyRefCon: nil, outClient: client)
Apple没有MIDINotifyProc的Swift示例或我想要使用的其他MIDI函数,我无法找出正确的方法参数类型。
答案 0 :(得分:1)
目前无法将Swift函数转换为C函数,因此不能仅使用Swift执行此操作。这里有一个关于如何尽可能使用Objective-C的示例:Objective-C Wrapper for CFunctionPointer to a Swift Closure