1
votes

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!

1
Is JGPixel a class or a structure in Obj-C?Pradeep K

1 Answers

1
votes

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.