2
我使用的功能需要UnsafePointer<String>
。'inout String'不能轉換爲'UnsafePointer <String>'
如何從字符串中獲得UnsafePointer<String>
?
試圖&someString
給我的錯誤:
'inout String' is not convertible to 'UnsafePointer<String>'
我使用的功能需要UnsafePointer<String>
。'inout String'不能轉換爲'UnsafePointer <String>'
如何從字符串中獲得UnsafePointer<String>
?
試圖&someString
給我的錯誤:
'inout String' is not convertible to 'UnsafePointer<String>'
&someString
創建CMutablePointer<String>
。
要將其轉換爲UnsafePointer
,最簡單的解決方法是調用特殊功能:
withUnsafePointer(&someString) { unsafePointer in
//do something with the unsafePointer
}
奇怪的是,現在這個生產'錯誤:(26,27)「字符串」是無法轉換爲「@lvalue如果字符串是一個常量,或者錯誤:(26,9)不能轉換表達式的類型'(inout String,((T6) - >($ T6) - > $ T5) - > ($ T6) - > $ T5) - > $ T5)'鍵入「Result」(如果它是一個變量) –