How to convert UInt8 byte array to string in Swift

前端 未结 14 2553
野的像风
野的像风 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:58

    Swifty solution

    array.reduce("", combine: { $0 + String(format: "%c", $1)})
    

    Hex representation:

    array.reduce("", combine: { $0 + String(format: "%02x", $1)})
    

提交回复
热议问题