0

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

Matthew Chung
  • 1,322
  • 1
  • 19
  • 31
  • The LLDB debugger is pretty bad on Swift in general and local variables and parameters in particular. There's not much you can do; what you are already doing (println) is often the best solution. - You might try downloading Xcode 6.2 beta as I have a sense it's a bit better. – matt Jan 09 '15 at 03:58
  • I downloaded the 6.2 beta and still the same problem. Anyways, thanks for letting me know about the state of lldb on XCode. – Matthew Chung Jan 09 '15 at 16:07
  • I can't reproduce the _exact_ problem but LLDB portrays a dictionary very badly (i.e. unhelpfully) on my machine too. – matt Jan 09 '15 at 16:50
  • 1
    I've resorted to doing stuff like this in lldb p println(json) – Matthew Chung Jan 12 '15 at 01:32
  • maybe [my answer](http://stackoverflow.com/a/33254508/3151066) will be helpful here – Julian Oct 21 '15 at 09:02

3 Answers3

13

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)

clearlight
  • 12,255
  • 11
  • 57
  • 75
1

in Swift 2 it is:

(lldb) p print(dict)
NSNoob
  • 5,548
  • 6
  • 41
  • 54
Developer Sheldon
  • 2,140
  • 1
  • 11
  • 17
1

Swift 3

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

(lldb) p dictionary.description
Jonathan Cabrera
  • 1,656
  • 1
  • 19
  • 20