打印字典的键和值

打印字典的键和值

本文介绍了Xcode 打印字典的键和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 7 中的打印描述给出了类似于下面的内存地址.尝试了所有选项,但得到这样的输出.

Print description in Xcode 7 is giving memory addresses similar to below. Tried all the options, but getting output like this.

▿ 3 elements
  ▿ [0] : 2 elements
    - .0 : Output
    ▿ .1 : 3 elements
      ▿ [0] : 2 elements
        - .0 : type
        - .1 : Output2 { ... }
      ▿ [1] : 2 elements
        - .0 : version
        - .1 : 1.0
      ▿ [2] : 2 elements
        - .0 : content
        ▿ .1 : 2 elements

如何改为打印字典的确切值?

How can I instead print the exact values of a dictionary?

推荐答案

我创建了这个测试字典:

I created this test dictionary:

let dict:Dictionary = ["key1": "value1", "key2": 42, "keyForColor": UIColor.redColor()]

然后我使用 po dict 并得到你描述的结果:

Then I used po dict and get the result you described:

po dict
▿ 3 elements
  ▿ [0] : 2 elements
    - .0 : "key1"
    - .1 : value1
  ▿ [1] : 2 elements
    - .0 : "keyForColor"
  ▿ [2] : 2 elements
    - .0 : "key2"

当你使用 po dict.description 时,你会得到:

When you use po dict.description, you get this:

po dict.description
"[\"key1\": value1, \"keyForColor\": UIDeviceRGBColorSpace 1 0 0 1, \"key2\": 42]"

这篇关于Xcode 打印字典的键和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:23