我正在尝试在 Xcode 中使用 Swift 为 AudioServicesAddSystemSoundCompletion 中的参数创建 AudioServicesSystemSoundCompletionProc 的实例,但失败了。
这是我到目前为止所得到的
func completionCallback(ssID:SystemSoundID,clientData:UnsafeMutablePointer<Void>) -> Void {
}
var foo:(ssID:SystemSoundID,clientData:UnsafeMutablePointer<Void>) -> Void = completionCallback;
AudioServicesAddSystemSoundCompletion(soundID, nil, nil, foo, nil);
我在一些指南的帮助下写了这篇文章,解释了如何在 Swift 中编写等效的 C 函数指针,但这会引发以下错误:
'(ssID: SystemSoundID, clientData: UnsafeMutablePointer<Void>) -> Void' is not convertible to 'AudioServicesSystemSoundCompletionProc'
文档显示了 Objective-C 声明:
typedef void (*AudioServicesSystemSoundCompletionProc) ( SystemSoundID ssID, void *clientData );
这是使用 Xcode 时显示的声明:
typealias AudioServicesSystemSoundCompletionProc = CFunctionPointer<((SystemSoundID, UnsafeMutablePointer<Void>) -> Void)>
我不确定如何在 Swift 中正确实现 AudioServicesSystemSoundCompletionProc。