如何在Swift中将字节转换为String?

时间:2016-12-15 15:52:33

标签: swift string byte

经过一段时间的搜索,我无法弄清楚如何获得这个简单的结果:

PFQuery *query = [PFQuery queryWithClassName:@"Cart"];
[query includeKey:@"Catalog"];
[query addAscendingOrder:@"desc"];
         or
[query addAscendingOrder:@"Catalog.desc"];

我尝试了this方法,在传入字节或字节数组时不会编译。

1 个答案:

答案 0 :(得分:3)

两种方式:

let s1 = String(byte, radix: 16, uppercase: true) // does not do 0-padding but works with
                                                  // all radices between 2 and 36

let s2 = String(format: "%02X", byte)             // very similar to C