我正在将Swift 2.x项目迁移到Swift 3。
我在使用Swift 3语法将UnsafeMutableBufferPointer<CChar>
转换为UnsafeMutablePointer<utsname>
时遇到问题。
Swift 2.x :
(ptr: inout UnsafeMutableBufferPointer<CChar>) -> DeviceTypes in
uname(UnsafeMutablePointer<utsname>(ptr.baseAddress))
答案 0 :(得分:1)
斯威夫特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)