iOS Simulator Document Directory Path

In one of the projects I am working on, the iOS app I am maintaining is temporarily saving images to the document directory of the app. The files need to survive a restart of the app or the phone, so we can't use the normal temp directory. Naturally, I wanted to check that the application is properly deleting the files after being done with them. In the past I navigated to ~/Library/Developer/CoreSimulator/Devices and used things like find to figure out the path to the document directory of the app.

That always took some time, and depending on the file type or name of question, didn't work at all. Fortunately, there is a simctl sub-command that gives you the path to the document directory given the app's Bundle Identifier.

xcrun simctl get_app_container booted org.example.myapp data

Just replace org.example.myapp with the Bundle Identifier of your app. The app needs to run in the simulator for this to work.

Instead of data, as last command parameter, there is also app and groups. The former returns the path to the app and the latter the path to the directory containing the data of App Groups you might have set up.