在 Swift 3.1 中,不推荐使用 UnsafeMutablePointer.initialize(from:)。Xcode 建议我改用 UnsafeMutableBufferPointer.initialize(from:) 。我有一个看起来像这样的代码块:
let pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 64)
pointer.initialize(from: repeatElement(0, count: 64))
由于弃用,该代码给了我一个编译时警告。所以我要把它改成:
let pointer = UnsafeMutablePointer<UInt8>.allocate(capacity: 64)
let buffer = UnsafeMutableBufferPointer(start: pointer, count: 64)
_ = buffer.initialize(from: repeatElement(0, count: 64))
这是正确的方法吗?我只是想确保我做得正确。