Find app data path for iOS simulator

Find the app data path with xcrun simctl for iOS simulator

When we develop iOS app, we usually need to find the data path for our app, and open the folder or navigate to the folder in Terminal . But it’s hard to find the path for me.

Solution #1

Print the data path on code, so I use the following code to print the Document path, and find the path on the log, then navigate to the path.let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let documentsDirectory = urls[0]print(documentsDirectory)

Solution #2

I find another tool together with xcode, which is xcrun simctl , with this tool, we can list devices, list applications, and get data folder for a specific application.

List devices

To list the devices, use the following command.# List all devices
xcrun simctl list devices# To list booted devices
xcrun simctl list devices | grep BootedSample output:
== Devices ==
-- iOS 11.0 --
-- iOS 15.4 --
   iPhone 8 (D51C816E-CCBE-46DE-B162-6CAA6ADD5AE6) (Shutdown)
   iPhone 8 Plus (8E462768-B9D8-4B8E-99B6-CC90B9A4C2A5) (Shutdown)
   iPhone 11 (7CCC24D3-E7FB-4382-B683-76E672DB0FB0) (Booted)
...

List installed apps

To list the app, the device should be booted, if only one simulator was booted, then the device id can be booted, if more than one simulator was booted, then we can pass the device id to list apps.

On the output, it has ApplicationType, which has two values: System and User.xcrun simctl listapps booted
xcrun simctl listapps <deviceId># Sample output:
   "com.swanwish.AudioPlayer" =     {
       ApplicationType = User;
       Bundle = "file:///.../Library/Developer/CoreSimulator/Devices/7CCC24D3-E7FB-4382-B683-76E672DB0FB0/data/Containers/Bundle/Application/AE4C5321-6F45-47FE-BACE-59AB873B75DA/AudioPlayer.app/";
       BundleContainer = "file:///.../Library/Developer/CoreSimulator/Devices/7CCC24D3-E7FB-4382-B683-76E672DB0FB0/data/Containers/Bundle/Application/AE4C5321-6F45-47FE-BACE-59AB873B75DA/";
       CFBundleDisplayName = AudioPlayer;
       CFBundleExecutable = AudioPlayer;
       CFBundleIdentifier = "com.swanwish.AudioPlayer";
       CFBundleName = AudioPlayer;
       CFBundleVersion = 1;
       DataContainer = "file:///.../Library/Developer/CoreSimulator/Devices/7CCC24D3-E7FB-4382-B683-76E672DB0FB0/data/Containers/Data/Application/78E2D7F5-CE1D-4B89-83B5-294E635A848B/";
       GroupContainers =         {
       };
       Path = ".../Library/Developer/CoreSimulator/Devices/7CCC24D3-E7FB-4382-B683-76E672DB0FB0/data/Containers/Bundle/Application/AE4C5321-6F45-47FE-BACE-59AB873B75DA/AudioPlayer.app";
       SBAppTags =         (
       );
   };

Get app data path

To get the data path for a specific app on specific device.xcrun simctl get_app_container booted <bundleId> data# For the example above, the bundle id is: com.swanwish.AudioPlayer
xcrun simctl get_app_container booted com.swanwish.AudioPlayer data# Sample output
.../Library/Developer/CoreSimulator/Devices/7CCC24D3-E7FB-4382-B683-76E672DB0FB0/data/Containers/Data/Application/78E2D7F5-CE1D-4B89-83B5-294E635A848B

The output is the value of DataContainer on the result of the list apps command.