Lorenzo
Lorenzo

Reputation: 3387

Document folder iOS Simulator

How is possible to find quickly the document folder (in the mac) of an App when I'm using the simulator? When I need to explore the document folder during the simulation of the App now I use a variable of the App to find the document folder path and I read the path during the debug (using a variable) but I think is not the best solution.

Upvotes: 46

Views: 28433

Answers (4)

Niklas
Niklas

Reputation: 25463

This is the best I could do:

echo "Documents directory"
device_id=$(xcrun simctl list devices | grep Booted | sed -n 's/^.*\([A-F0-9]\{8\}-\([A-F0-9]\{4\}-\)\{3\}[A-F0-9]\{12\}\).*$/\1/p')
for folder in ~/Library/Developer/CoreSimulator/Devices/$device_id/data/Containers/Shared/AppGroup/*; do
  documents_directory="$folder/File Provider Storage"

  if [[ -a "$folder/File Provider Storage" ]]; then
    echo $documents_directory
    break
  fi
done

Upvotes: 0

Jeremy Huddleston Sequoia
Jeremy Huddleston Sequoia

Reputation: 23651

Open up Terminal.app and run:

xcrun simctl get_app_container booted [app identifier] data

You can even setup an alias to change to the directory, like:

alias cdmyapp='cd $(xcrun simctl get_app_container booted com.mycompany.myapp data)'

Upvotes: 30

Johan
Johan

Reputation: 2507

Set and hit a breakpoint in the app, and write the following in the Xcode Console (next to the Variables View):

po NSHomeDirectory()

Then in Finder hit Shift+CMD+G, paste the path returned above without the quotation marks and hit enter.

Upvotes: 136

Tomasz Rejdych
Tomasz Rejdych

Reputation: 434

I have 2 solution

  • Simpholders or free and open source alternative OpenSim
  • A simple script that opens the finder window with the recently launched application on the iOS simulator

deviceId=$(xcrun simctl list devices | grep Booted | sed -n 's/^.([A-F0-9]{8}-([A-F0-9]{4}-){3}[A-F0-9]{12}).$/\1/p') applicationFolder=~/Library/Developer/CoreSimulator/Devices/$deviceId/data/Containers/Data/Application/ applicationFolder=$applicationFolder$(ls -Art $applicationFolder | tail -n 1) open $applicationFolder

Upvotes: 6

Related Questions