Reputation: 1639
I have the following code, in objective 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)!'
Can anyone help explain where i'm going wrong, and how I can learn more about this error. Thanks!
Upvotes: 1
Views: 61
Reputation: 9044
You need to use the withUnsafeMutablePointer
function as documented here. 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. Fixed above.
Upvotes: 1