[英]Converting obj-c code to swift 2 block issue
I have the following code, in objective C. 我在目标C中有以下代码。
[pixelData processPixelsWithBlock:^(JGPixel *pixel, int x, int y) {
}];
now, to me, the swift equivalent would be 现在,对我来说,迅速的等效
pixelData.processPixelsWithBlock({(pixel: JGPixel, x: Int, y: Int) -> Void in
})
however, that is throwing an error of 但是,这将引发错误
Cannot convert value of type '(JGPixel, Int, Int) -> Void' to expected argument type '((UnsafeMutablePointer, Int32, Int32) -> Void)!' 无法将类型'((JGPixel,Int,Int)-> Void'的值转换为预期的参数类型'(((UnsafeMutablePointer,Int32,Int32)-> Void)!'
Can anyone help explain where i'm going wrong, and how I can learn more about this error. 任何人都可以帮忙解释我要去哪里哪里以及如何了解有关此错误的更多信息。 Thanks!
谢谢!
You need to use the withUnsafeMutablePointer
function as documented here . 您需要使用此处记录的
withUnsafeMutablePointer
函数。 Something along the lines of: 类似于以下内容:
var pixel: JGPixel = // whatever
withUnsafeMutablePointer(&pixel, { (ptr: UnsafeMutablePointer<JGPixel>) -> Void in
pixelData.processPixelsWithBlock({(ptr, x: Int, y: Int) -> Void in
})
})
EDIT: Just realised I forgot to pass ptr to the function properly. 编辑:刚意识到我忘了正确地将ptr传递给函数。 Fixed above.
固定在上面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.