Cannot find where to place files for the Xcode simulator on my Mac

430 Views Asked by At

I am having trouble finding where to place files on my Mac so that my Xcode simulator sees them.

Working on a "file upload" section for my app. Before I call the UIDocumentPickerViewController, I do call my own function printSimDir which I use to open the proper folder on my Mac so I can throw my files in there.

And in there I have three files: "blank_inv, invoice_001.cvs, and example.mp3"

However, in my simulator, I don't see these files. I do however keep seeing one xls file that is not any of three above files. So at one point I did get this right. But not anymore.

I realize that my problem might also be in how I am calling the UIDocumentPickerViewController so am including that code as well.

case ButtType.file.rawValue:
    printSimDir()

    let supportedTypes: [UTType] = [UTType.spreadsheet, UTType.commaSeparatedText, .mp3]
    let pickerViewController = UIDocumentPickerViewController(forOpeningContentTypes: supportedTypes)
    pickerViewController.delegate = self
    pickerViewController.allowsMultipleSelection = false
    present(pickerViewController, animated: true, completion: nil)


...


extension UploadInv:  UIDocumentPickerDelegate {

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
    
    for url in urls {
        guard url.startAccessingSecurityScopedResource() else {
            print ("error")
            return
        }
        
        xFile = XFile(fileUrl: url, key: "filename")
        myStartUPButt.isEnabled = true
        
        do { url.stopAccessingSecurityScopedResource() }
        myStatus.text = xFile?.filename
    }
}

func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
    controller.dismiss(animated: true, completion: nil)
    }
}   

printSimDir()

func printSimDir(){
    //  tried the commented code as well
    //  let fManager = FileManager.default
    //  guard let url = fManager.urls(for: .documentDirectory, in: .userDomainMask).first else {return}
    //  print ("\(url)")
    
    #if targetEnvironment(simulator)
    if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
        print("Documents Directory: \(documentsPath)")
    }
    #endif
}
1

There are 1 best solutions below

0
On

For those who come across this. Not sure where I found the answer, but it's quite simple.

Simply drag and drop the files you want from your Mac to the Xcode simulator's Home Screen. Currently have only tried them one at a time.

Is this the proper answer? I do not know. But it does work.

Haven't tried every way to do this, (one at a time, multiple files at once, multiple simulators, etc.) But even after a Mac restart the files are still there.