我正在尝试打印由原始指针指向的指针的内容,但是当我打印或NSLog时,我得到指针的值而不是指针所指向的内存的内容。如何打印指针指向的内存内容?以下是我的代码:
let buffer = unsafeBitCast(baseAddress, to: UnsafeMutablePointer<UInt32>.self)
for row in 0..<bufferHeight
{
var pixel = buffer + row * bytesPerRow
for _ in 0..<bufferWidth {
// NSLog("Pixel \(pixel)")
print(pixel)
pixel = pixel + kBytesPerPixel
}
}
答案 0 :(得分:2)
pixel
是指向UInt32
的指针,用于打印指向的
你必须取消引用它的价值:
print(pixel.pointee)
请注意,递增指针是以步幅为单位完成的 指向的值,所以你的
pixel = pixel + kBytesPerPixel
将地址递增4 * kBytesPerPixel
个字节,这是
可能不是你想要的。