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

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


        
16条回答
  •  粉色の甜心
    2020-12-07 10:23

    Casting a dictionary to 'AnyObject' was the simplest solution for me:

    let dictionary = ["a":"b",
                      "c":"d",
                      "e":"f"]
    print("This is the console output: \(dictionary as AnyObject)")
    

    This is easier to read for me than the dump option, but note it won't give you the total number of key-values.

提交回复
热议问题