Oliver
Oliver

Reputation: 23550

XCode 4 - Easily access "Documents" folder of an app installed onto the simulator

When running an app onto the simulator, it creates a folder onto the Mac to contain the apps datas in a "Documents" folder. This folder is changed when you delete the app from the simulator, or when you change some app settings into XCode. When you have dozens of apps, it's a nightmare to find the good one by hand.

Is there a way to easily access this folder ?

Upvotes: 4

Views: 7601

Answers (5)

Jari Keinänen
Jari Keinänen

Reputation: 1439

Bazinga's answer (along with sebrenner's deprecation notice) is great for Objective-C.

For Swift, the equivalent would be:

let appFolderPath = NSBundle.mainBundle().resourcePath
let fileManager = NSFileManager.defaultManager()
print("App Directory is: \(appFolderPath)")
print("Directory Contents:\n \(fileManager.contentsAtPath(appFolderPath!))")

Upvotes: 0

sebrenner
sebrenner

Reputation: 83

directoryContentsAtPath: is deprecated.

Instead use contentsOfDirectoryAtPath:error:

 //App Directory & Directory Contents
   NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
   NSFileManager *fileManager = [NSFileManager defaultManager];  
   NSLog(@"App Directory is: %@", appFolderPath);
    NSLog(@"Directory Contents:\n%@", [fileManager contentsOfDirectoryAtPath:appFolderPath error:nil]);

See https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/#//apple_ref/occ/instm/NSFileManager/directoryContentsAtPath:

Upvotes: 0

us_david
us_david

Reputation: 4917

The location in general is: /Users/yourusername/Library/Application Support/iPhone Simulator/7.1/Applications/appcode/Documents/yourdocuments.db

'yourusername': username you used for your development machine
'appcode': application identifier that is a series of numbers such as: 32F88907-B348-4764-9819-A5B6F9169FB7 (unique to your app)

the version number (7.1) in the path depends on the version of Xcode and hence the simulator.

Upvotes: 0

Bazinga
Bazinga

Reputation: 2466

Just gonna try answering. How about logging it, like this:

    //App Directory & Directory Contents
   NSString *appFolderPath = [[NSBundle mainBundle] resourcePath];
   NSFileManager *fileManager = [NSFileManager defaultManager];  
   NSLog(@"App Directory is: %@", appFolderPath);
   NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]);

Upvotes: 6

spring
spring

Reputation: 18517

What I do is create a link in the Finder sidebar to the simulator folder. It is approximately:

/Users/userName/Library/Application/Support/iPhone/Simulator/5.0/Applications/

Then I have that folder sorted by 'last modified'. Once I find the app folder for the app I am working on, I expand it to display the app (and see the app name) and also set a color on the folder. The Finder sometimes doesn't keep the folder sorted by 'last modified' unless the window is closed and reopened.

Upvotes: 4

Related Questions