68

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.

mfaani
  • 33,269
  • 19
  • 164
  • 293
Will Pragnell
  • 3,073
  • 1
  • 20
  • 21

5 Answers5

129

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

Will Pragnell
  • 3,073
  • 1
  • 20
  • 21
pstoppani
  • 2,531
  • 1
  • 20
  • 20
26

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.

James Perih
  • 1,360
  • 1
  • 17
  • 19
  • I tried to replace container but not changing anything i've changed identifier, executableName, etc but after replacing nothing shows as per new value which i've set – Mrugesh Tank May 21 '15 at 09:16
  • 3
    For those unfamiliar here's how to open the file. It is a container, so in Finder you have to left-click to the file and choose "Show Package Contents". Then you browse like any other folder you already have. – Andrej Aug 26 '15 at 10:44
9

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).

SVD
  • 4,743
  • 2
  • 26
  • 38
  • 1
    A useful tip, thanks! However it does seem like a very roundabout way of achieving something that should hopefully be a bit more straight forward. – Will Pragnell Sep 14 '11 at 07:51
  • Yes, but it would seem this is the only way to look at the file - or do what Lio suggests. Perhaps on a jailbroken device you could ssh into the device as root and look at any files. – SVD Sep 14 '11 at 17:09
9

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.

brainjam
  • 18,863
  • 8
  • 57
  • 82
Will Pragnell
  • 3,073
  • 1
  • 20
  • 21
  • 4
    The .xcappdata download isn't a file -- it's the whole sandbox directory (at least the data part)! Just look inside -- Terminal is a good way to do this, analogous to looking inside a .app at its constituents. It isn't necessary to change the extension, though if you eliminate the extension altogether you might help Finder with it's confusion over the "type" of the "file". The directory even contains an AppDataInfo.plist file that is a binary-format plist that shows you what is there. – Scott Marks Sep 26 '11 at 23:51
  • 1
    The AppDataInfo.plist file is actually an excerpt from the app's Info.plist. – Scott Marks Sep 27 '11 at 00:10
  • 3
    To view it's contents in Finder, right click and select 'Show Package Contents' – Dean Jan 11 '13 at 17:51
  • @Will Pragnell I want to hide some of the files in sandbox from my application user is it possible? – vignesh kumar Nov 13 '13 at 13:05
3

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];.

Lio
  • 4,225
  • 4
  • 33
  • 40
  • 1
    While this is very useful, I'm afraid it's not quite what I'm after. I realise that in most cases I can simply use this to view the contents of an object just before writing to disk (or just after reading), but I was wondering if there's a quick and easy way to simply examine *actual files*. – Will Pragnell Sep 14 '11 at 07:50
  • If you are on the simulator, you can NSLog the path of the file, copy it from the console and open it in the terminal using 'open thePath' – Lio Sep 14 '11 at 11:47