Matthew Chung
Matthew Chung

Reputation: 1342

How to print out the value of an an Dictionary in xcode 6.1.1

When debugging in Swift, I'm having problems reading out variables. In this example, I'm trying to print out the value of the info object coming back from an image picker. (please see link to screenshot on dropbox)

Using println as you can see from the screenshot line 19 works fine. It prints out the first block of stuff on the output.

After that, I tried doing a po info as well as highlighting the variable and clicking the eye to print the description. Both of those printed out an empty {} which doesn't make sense to me, since there is clearly stuff there.

So my question is, is there an lldb command or easy way to view/print out the values of the variables - opposed to an empty {} I find I can't consistently observe the values of my variables which is frustrating.

https://dl.dropboxusercontent.com/u/45836281/debug.png

Upvotes: 0

Views: 2321

Answers (3)

Jonathan Cabrera
Jonathan Cabrera

Reputation: 1751

Swift 3

If you don't like the default lldb reprensentation, you can also:

(lldb) p dictionary.description

Upvotes: 1

Developer Sheldon
Developer Sheldon

Reputation: 2160

in Swift 2 it is:

(lldb) p print(dict)

Upvotes: 1

clearlight
clearlight

Reputation: 12615

Workaround for lldb limitations (example):

(lldb) p println(countryHash!)

Output example:

[botswana: bw, united states minor outlying islands: um, isle of man: im, czech republic: cz, mauritius: mu, jersey: je, maldives: mv, uruguay: uy, barbados: bb, serbia: rs, qatar: qa, montenegro: me, grenada: gd, syrian arab republic: sy, samoa: ws, greenland: gl, iraq: iq, malawi: mw, croatia: hr, saint lucia: lc, seychelles: sc, egypt: eg, ... ]

(note: the list of countries is actually complete in the lldb output, but merely truncated above to avoid wasting space in this answer)

Upvotes: 13

Related Questions