小编Dav*_*son的帖子

如何在Swift中实现AudioServicesSystemSoundCompletionProc?

我正在尝试并且未能使用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.

c xcode swift

4
推荐指数
3
解决办法
1873
查看次数

标签 统计

c ×1

swift ×1

xcode ×1