Is there a way to pretty print Swift dictionaries to the console?

前端 未结 16 1003
北海茫月
北海茫月 2020-12-07 09:33
NSDictionary *dictionary = @{@\"A\" : @\"alfa\",
                             @\"B\" : @\"bravo\",
                             @\"C\" : @\"charlie\",
                       


        
16条回答
  •  天涯浪人
    2020-12-07 10:22

    Pretty print from Data object:

    let jsonObj = try JSONSerialization.jsonObject(with: data, options: [])
                let jsonData = try JSONSerialization.data(withJSONObject: jsonObj, options: [.prettyPrinted])
                print(String(data: jsonData, encoding: .utf8)!)
    

提交回复
热议问题