我正在使用一个UnsafePointer<String>
的函数。
如何从字符串中获取UnsafePointer<String>
?
尝试&someString
会给我一个错误:
'inout String' is not convertible to 'UnsafePointer<String>'
答案 0 :(得分:2)
&someString
创建CMutablePointer<String>
。
要将其转换为UnsafePointer
,最简单的解决方案是调用特殊函数:
withUnsafePointer(&someString) { unsafePointer in
//do something with the unsafePointer
}