Ios 如何在Swift中打印指针内容
我试图打印原始指针指向的指针的内容,但当我打印或NSLog时,我得到的指针值比指针指向的内存内容的值要大。如何打印指针指向的内存内容?下面是我的代码:Ios 如何在Swift中打印指针内容,ios,swift,unsafemutablepointer,Ios,Swift,Unsafemutablepointer,我试图打印原始指针指向的指针的内容,但当我打印或NSLog时,我得到的指针值比指针指向的内存内容的值要大。如何打印指针指向的内存内容?下面是我的代码: let buffer = unsafeBitCast(baseAddress, to: UnsafeMutablePointer<UInt32>.self) for row in 0..<bufferHeight { var pixel = buffer + row * bytesPer
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
}
}
let buffer=unsafeBitCast(基址,收件人:UnsafeMutablePointer.self)
对于0中的行,..像素
是指向UInt32
的指针,用于打印指向的
您必须取消引用它的值:
print(pixel.pointee)
请注意,递增指针是以步长为单位的
指向值,因此您的
pixel = pixel + kBytesPerPixel
将地址增加4*kBytesPerPixel
字节,这
可能不是您想要的。好的,我用UInt8替换了UInt32,因此指针现在是UInt8。如何将此UInt8指针键入UInt32*,然后打印整数?