【发布时间】:2015-06-25 07:13:26
【问题描述】:
我想从 C 库中获取一个 wchar_t 数组,并将其转换为 swift 数据结构,我的代码在这里:
func getResults(recognizer: UnsafeMutablePointer<Void>, stroke: UnsafeMutablePointer<Int32>, touchState: Int32) -> [String] {
var bufLen : Int32
var buf = UnsafeMutablePointer<wchar_t>.alloc(Int(bufLen))
getRecognition(recognizer, stroke, touchState, buf, bufLen)
var results = String.fromCString(buf)! //this line has an error, cause the buf is wchar_t*, not char*
}
如何将 buf 转换为 swift 数据结构?
我知道如果buf是UnsafeMutablePointer<Int8>.alloc(Int(bufLen)),我们可以使用String.fromCString(buf)!转换它。
如果我 println(buf[0]),它打印一个整数 67,它是 'C' 的 ascii 值,我怎样才能 println(buf[0]) 作为 'C' 而不是 0? 谢谢!
【问题讨论】: