Working with C strings in Swift, or: How to convert UnsafePointer to CString

后端 未结 2 786
夕颜
夕颜 2020-12-15 16:24

While playing with Standard C Library functions in Swift, I came across problems when passing C strings around. As a simple example (just to demonstrate the problem), the St

2条回答
  •  失恋的感觉
    2020-12-15 17:22

    The String struct in Swift has an init routine you can use like:

    let myString = String(cString: myUnsafePointer)
    

    see also init(cString: UnsafePointer)

提交回复
热议问题