簡體   English   中英

將obj-c代碼轉換為swift 2塊問題

[英]Converting obj-c code to swift 2 block issue

我在目標C中有以下代碼。

[pixelData processPixelsWithBlock:^(JGPixel *pixel, int x, int y) {

}];

現在,對我來說,迅速的等效

pixelData.processPixelsWithBlock({(pixel: JGPixel, x: Int, y: Int) -> Void in

})

但是,這將引發錯誤

無法將類型'((JGPixel,Int,Int)-> Void'的值轉換為預期的參數類型'(((UnsafeMutablePointer,Int32,Int32)-> Void)!'

任何人都可以幫忙解釋我要去哪里哪里以及如何了解有關此錯誤的更多信息。 謝謝!

您需要使用此處記錄的withUnsafeMutablePointer函數。 類似於以下內容:

var pixel: JGPixel = // whatever
withUnsafeMutablePointer(&pixel, { (ptr: UnsafeMutablePointer<JGPixel>) -> Void in
    pixelData.processPixelsWithBlock({(ptr, x: Int, y: Int) -> Void in

    })
})

編輯:剛意識到我忘了正確地將ptr傳遞給函數。 固定在上面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM