How to convert UInt8 byte array to string in Swift

前端 未结 14 2522
野的像风
野的像风 2020-12-05 06:29

I am facing problems while converting UInt8 Byte array to string in swift. I have searched and find a simple solution

String.stringWithBytes(buf         


        
14条回答
  •  一整个雨季
    2020-12-05 06:50

    Swift 3

    the following was giving me an error because of "NSUTF8StringEncoding":

    String(data: nsdata, encoding: NSUTF8StringEncoding)! 
    

    this worked for me in swift 3:

    let xmlStr:String = String(bytes: data!, encoding: String.Encoding.utf8)!
    

提交回复
热议问题