mrd
mrd

Reputation: 4699

How to view the files/directories created by my iOS app in Xcode

I have an app and I want to examine the files and directories the app creates on my iPhone in Xcode 9.

How can I do that?

Upvotes: 7

Views: 10717

Answers (5)

Ori C.
Ori C.

Reputation: 132

How to find the path to the documents directory in Swift?

You can use the following command in the Xcode debug console to get the path to the documents directory:

po FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first

This will print the URL for the documents directory in your app's sandboxed environment. The po command evaluates the expression and outputs the result in a human-readable format.

For example, the output might look like this:

▿ Optional<URL>
  - some : file:///Users/username/Library/Developer/CoreSimulator/Devices/.../Documents/

Upvotes: -2

ToooLazy
ToooLazy

Reputation: 111

You can view your directories in your physical device too. To do so, just add two keys in your info.plist file

<key>UIFileSharingEnabled</key>
<true/> 

<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

UIFileSharingEnabled key will enable "Application supports iTunes file sharing"

LSSupportsOpeningDocumentsInPlace key will enable "Supports opening documents in place"

Then go your physical device's files to see your folder(s).

Upvotes: 6

SWAT
SWAT

Reputation: 1158

Go to:

Window -> Devices and Simulators -> Select your device -> Select your app

Use the "gear" icon and "Download Container". Save this file in any location you like and access it by right clicking the file and "Show Package Content"

This will reveal the files that are saved in your app's document directory and other folders within the app. This will not self update on your next run, of course.

If you are using a simulator, you may access the contents folder by going to : ~/Library/Developer/CoreSimulator/Devices/[DeviceID]/

Upvotes: 16

Manish Malviya
Manish Malviya

Reputation: 586

If you have a physical device you can add UIFileSharingEnabled key in info.plist and set it value to YES

then run your app

open iTunes select device and goto file sharing and select your app you will be shown files created by your app

and if you don't have a physical device then only option you have is Fiona's answer

Upvotes: 7

User1075
User1075

Reputation: 885

Try this

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];
NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];
NSLog(@"Source Path: %@\n Documents Path: %@ \n Folder Path: %@", sourcePath, documentsDirectory, folderPath);

This will get you the file path. Now in your Desktop Open Finder, press Shift + Command + G, paste the path and press Go.

Upvotes: 1

Related Questions