我正在尝试并且未能使用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);
Run Code Online (Sandbox Code Playgroud)
我在一些指南的帮助下写了这篇文章,解释了如何在Swift中编写等效的C函数指针,但这引发了这个错误:
'(ssID: SystemSoundID, clientData: UnsafeMutablePointer<Void>) -> Void' is not convertible to 'AudioServicesSystemSoundCompletionProc'
Run Code Online (Sandbox Code Playgroud)
文档显示了Objective-C声明:
typedef void (*AudioServicesSystemSoundCompletionProc) ( SystemSoundID ssID, void *clientData );
Run Code Online (Sandbox Code Playgroud)
这是使用Xcode时显示的声明:
typealias AudioServicesSystemSoundCompletionProc = CFunctionPointer<((SystemSoundID, UnsafeMutablePointer<Void>) -> Void)>
Run Code Online (Sandbox Code Playgroud)
我不确定如何在Swift中正确实现AudioServicesSystemSoundCompletionProc.