'inout String'不能转换为'UnsafePointer <string>'</string>

时间:2014-06-11 20:42:53

标签: swift unsafe-pointers

我正在使用一个UnsafePointer<String>的函数。

如何从字符串中获取UnsafePointer<String>

尝试&someString会给我一个错误:

'inout String' is not convertible to 'UnsafePointer<String>'

1 个答案:

答案 0 :(得分:2)

&someString创建CMutablePointer<String>

要将其转换为UnsafePointer,最简单的解决方案是调用特殊函数:

withUnsafePointer(&someString) { unsafePointer in
    //do something with the unsafePointer
}