正如标题所说,在
swift中将UnsafeMutablePointer转换为String的正确方法是什么?
//lets say x = UnsafeMutablePointer<Int8> var str = x.memory.????
解决方法
如果指针指向以NUL结尾的UTF-8字节的C字符串,则可以执行以下操作:
import Foundation let x: UnsafeMutablePointer<Int8> = ... // or UnsafePointer<Int8> // or UnsafePointer<UInt8> // or UnsafeMutablePointer<UInt8> let str = String(cString: x)