在Objetive-C中,当我想要指针的设置/更改值时.我用
*pointer = value
Run Code Online (Sandbox Code Playgroud)
但是在Swift中,如何获取/设置指针的值?
我正在使用位图像素:
NSUInteger offsetPixelCountForInput = ghostOrigin.y * inputWidth + ghostOrigin.x;
for (NSUInteger j = 0; j < ghostSize.height; j++) {
for (NSUInteger i = 0; i < ghostSize.width; i++) {
UInt32 * inputPixel = inputPixels + j * inputWidth + i + offsetPixelCountForInput;
UInt32 inputColor = *inputPixel;
newR = MAX(0,MIN(255, newR));
newG = MAX(0,MIN(255, newG));
newB = MAX(0,MIN(255, newB));
*inputPixel = RGBAMake(newR, newG, newB, A(inputColor));
}
}
Run Code Online (Sandbox Code Playgroud)
所以我想将这段代码转换成Swift,但我仍然坚持使用指针.
23.03.2016 - 更新代码
var inputPixels:UnsafeMutablePointer<UInt32> = nil
inputPixels …Run Code Online (Sandbox Code Playgroud)