Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C Swift 3中的GLFW回调签名_C_Swift_Swift3_Glfw - Fatal编程技术网

C Swift 3中的GLFW回调签名

C Swift 3中的GLFW回调签名,c,swift,swift3,glfw,C,Swift,Swift3,Glfw,我正在尝试在Swift 3中设置一个简单的GLFW应用程序。目前我一直在尝试设置回调函数 func setupGLFW() { ... glfwSetErrorCallback(errorCallback) ... } func errorCallback(error: Int32, description: UnsafePointer<Int8>) { ... } 尝试: func errorCallback(error: Int32, description:

我正在尝试在Swift 3中设置一个简单的GLFW应用程序。目前我一直在尝试设置回调函数

func setupGLFW() {
  ...
  glfwSetErrorCallback(errorCallback)
  ...
}

func errorCallback(error: Int32, description: UnsafePointer<Int8>) {
  ...
}
尝试:

func errorCallback(error: Int32, description: UnsafePointer<Int8>?) {
func errorCallback(错误:Int32,描述:UnsafePointer?){
(请不要错过
未安全指针之后的


在Swift 3中,可空指针作为可选指针导入,因此您需要

您可以在调用
glfwSetErrorCallback
的位置内联回调:

glfwSetErrorCallback { (error, description) in
    //
}
或者,使用存储在变量中的闭包:

let callback: GLFWerrorfun = { (error, description) in
    //
}

glfwSetErrorCallback(callback)
通过Option+左键单击符号,您可以看到此typedef如何桥接到Swift:


在本例中,我没有实际的GLFW头,所以我只是在桥接头中删除了声明。您生成的接口可能会显示更多信息。

谢谢!虽然是决定,但我接受了OOPers的答案,因为它显示了确切的签名。@MichaelWeis您知道您也可以将类型添加到我答案中的参数中吗对吗?如果Swift再次更改类型会发生什么?你会回到这里问同样的问题。通常,我更喜欢让编译器推断参数类型。对于实际代码,我也更喜欢类型推断,但OOPers的回答帮助我理解了我的签名不匹配的原因。@MichaelWeiss你还可以看到C类型是如何桥接到Sw的ift by选项+左键单击符号以查看生成的界面。
glfwSetErrorCallback { (error, description) in
    //
}
let callback: GLFWerrorfun = { (error, description) in
    //
}

glfwSetErrorCallback(callback)