我知道CString可以使用UnsafePointer初始化,但是如何使用ConstUnsafePointer创建它
代码错误:ConstUnsafePointer无法转换为UnsafePointer
var result:ConstUnsafePointer = sqlite3_column_text(stmt, num)
let cstr:CString = CString(result)
或如何将其转换为UnsafePointer
答案 0 :(得分:2)
您只需要查看UnsafePointer
:
var result: ConstUnsafePointer<UInt8> = sqlite3_column_text(stmt, num)
let cstr: CString = CString(UnsafePointer<UInt8>(result))
答案 1 :(得分:1)
请用变量替换LENGTH。
var result: ConstUnsafePointer = sqlite3_column_text(stmt, num)
var resultToString: NSString = NSString(bytes: result, length: LENGTH, encoding: NSUTF8StringEncoding)
var cstring: CString = resultToString.UTF8String