Converting from Swift string to const char*

前端 未结 4 435
渐次进展
渐次进展 2020-12-03 22:54

I\'m trying to pass a const char * to an old C library converted from a Swift string in Swift.

This is the C function I\'m calling:

artnet_node artne         


        
4条回答
  •  -上瘾入骨i
    2020-12-03 23:46

    You didn't specify what your Swift array contains. In any case, you need to convert your Swift array to an array of Int8:

    let str = "Hello world"
    let cArray = str.cString(using: .utf8)
    
    artnet_new(cArray, 1)
    

提交回复
热议问题