我有一個Int
我想要複製到類型的指針UnsafeMutablePointer<Int32>?
複製詮釋到UnsafeMutablePointer
我試圖將其轉換爲數據,然後將其複製,但複製功能參數是類型的UnsafeMutablePointer<UInt8>
這是我已經試過:
var sizePointer: UnsafeMutablePointer<Int32>?
var numOfBytes = 100
var sizeData = Data(bytes: &(numOfBytes), count: MemoryLayout<Int>.size)
//What's now? How to copy it to the pointer?
//sizeData.copyBytes(to: size, count: MemoryLayout<Int>.size) not working
編輯:
我有以下的功能,即獲得一個指針。我需要將int複製到該地址。
func f(pointer: UnsafeMutablePointer<Int32>?) {
var numOfBytes = 100
//copy numOfBytes to the pointer's address
}
我編輯的問題 – Roee84