I created a struct in Swift called RGB, simple enough:
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 } } And I have a pointer var imageData: UnsafeMutablePointer<PixelRGB>!.
I wish to malloc some space for this pointer, but malloc returns UnsafeMutablePointer<Void> and I cannot cast it like below:
imageData = malloc(UInt(dataLength)) as UnsafeMutablePointer<PixelRGB> // 'Void' is not identical to `PixelRGB` Anyway to solve this? Thank you for your help!
imageData = UnsafeMutablePointer<PixelRGB>.alloc(dataLength)?PixelRGB?