Is it possible to view the contents of files in the iOS Application sandbox while debugging?

I'd like to check the contents of an XML file at a specific point of execution while debugging in Xcode. Is it possible to view the contents of the file, either through the Organizer (I'm debugging using actual hardware devices, not the simulator), or by typing in some sort of command into the output/console?

I am using Xcode 4.


Solution 1:

Simply open the organiser and click the 'Download' button at the bottom, then right click on the xcappdata file and select Show Package Contents.

Solution 2:

Updated answer for Xcode 6:

The Devices tab now has it's own window (Window -> Devices). Find your Device, then your App. There is no 'download' button (unless the log window is visible... then the Download icon there actually saves the Log).

If you DOUBLE-CLICK on your app, a new window will become visible that shows a read-only, non-interactive representation of that app's sandbox.

To download the app container, select an app, click the "Gear" and "Download Container." It'll take a bit of a while, during which time there is no indication of the progress; but a Finder window will appear, showing with your .xcappdata file. You can also "Replace Container" which looks cool and exciting.

Solution 3:

You could enable file sharing (set the UIFileSharingEnabled flag in info.plist) and store the file where it can be accessed via iTunes (i.e. in the Documents folder).

Solution 4:

I have just discovered that you can in fact save the entire contents of the sandbox to disk at any time. Simply open the organiser and click the 'Download' button at the bottom. This saves the sandbox to disk as a .xcappdata file. I'm not sure how to open this as it is, but I have found that if you change the file extension to .xml, you can browse it using finder just like a normal directory.

It's a shame you can't download single files if required and that the whole process is a little cumbersome, but it does allow me to achieve what I wanted in the end.

Solution 5:

You can always set a breakpoint and then, in the console, print the contents of the object you want to examine using 'po'. Example: gdb> po [NSDictionary dictionaryWithContentsOfFile: filePath];.