ho creato una struttura a Swift chiamato RGB, abbastanza semplice:Typecast UnsafeMutablePointer <Void> a UnsafeMutablePointer <#Struct tipo #>
struct PixelRGB {
var r: CUnsignedChar = 0
var g: CUnsignedChar = 0
var b: CUnsignedChar = 0
init(red: CUnsignedChar, green: CUnsignedChar, blue: CUnsignedChar) {
r = red
g = green
b = blue
}
}
E ho un puntatore var imageData: UnsafeMutablePointer<PixelRGB>!
.
desidero malloc po 'di spazio per questo puntatore, ma malloc
rendimenti UnsafeMutablePointer<Void>
e non riesco a lanciarla come di seguito:
imageData = malloc(UInt(dataLength)) as UnsafeMutablePointer<PixelRGB> // 'Void' is not identical to `PixelRGB`
Comunque per risolvere questo problema? Grazie per l'aiuto!
Come su 'imageData = UnsafeMutablePointer .alloc (dataLength)'? –
matt
@matt Questa dovrebbe essere una risposta. –
Okey-dokey, lo farà. – matt