Search code examples
swiftxcodecsvexportios-simulator

How to export a bulk of csv from Xcode simulator to mac?


In Xcode using simulator I create and save certain amount of csv files into path:

let path = try FileManager.default.url(for: .documentDirectory,
                                               in: .allDomainsMask,
                                               appropriateFor: nil,
                                               create: false)

and I want to export them as a package (around 1gb big) to /Users/User/Documents/ on my Mac.

How to extract them from the simulator app?


Solution

  • The Documents directory will be stored in the path (at least Xcode 11+):

    ~/Library/Developer/CoreSimulator/Devices/{Device Identifier (GUID)}/data/Containers/Data/Application/{App Identifier (GUID)}/Documents

    You should find the CSV files in that folder. You can find the Device Identifier by navigating to Window->Devices and Simulators, then click on Simulators segment control and select the current simulator device on the left. The right panel should then show the simulator details, copy the value in Identifier: field.

    A quick way to find the App ID (and the path to all CSVs) is to run the following command in the Terminal, however, this will show all apps on that particular simulator with files of filetype .csv:

    cd ~/Library/Developer/CoreSimulator/Devices/{Device GUID}/data/Containers/Data/Application && find . -name '*.csv'
    

    This will return something like:

    ./{App GUID}/Documents/{Filename}.csv