gpt4 book ai didi

Swift3 - 如何将 UnsafeMutableBufferPointer 转换为 UnsafeMutablePointer

转载 作者:行者123 更新时间:2023-11-28 15:53:25 24 4
gpt4 key购买 nike

我正在将 Swift 2.x 项目迁移到 Swift 3。

我在转换 UnsafeMutableBufferPointer<CChar> 时遇到问题至 UnsafeMutablePointer<utsname>在 Swift 3 语法中。

swift 2.x:

(ptr: inout UnsafeMutableBufferPointer<CChar>) -> DeviceTypes in
uname(UnsafeMutablePointer<utsname>(ptr.baseAddress))

最佳答案

swift 3:

(ptr: inout UnsafeMutableBufferPointer<CChar>) -> DeviceTypes in

guard let pointer = ptr.baseAddress?.withMemoryRebound(to: utsname.self, capacity: 1, { ptr in
return ptr
}) else {
return DeviceTypes.unrecognized
}
uname(pointer)

关于Swift3 - 如何将 UnsafeMutableBufferPointer<CChar> 转换为 UnsafeMutablePointer<utsname>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com