Drop file not found on MacBook Air

Hello everyone, I am new to swift development and I am currently facing a "bug".

I am building, an app on my Mac mini. It's working fine on my machine but when exporting the executable on a MacBook Air, one of my feature does not work anymore.

I should be able to drag and drop a PDF which should be copy to my App document folder. But for some reason it won't work.

I should add that :

  • The app is sandboxed
  • I tried to build the app on the MacBook Air and it does not work either.
  • I gave all the permission to the app in the MacBook Air parameter menu.
  • I have another drag and drop functionality with read a csv file, and it works.

With Xcode, the error message was about : file not found (after being read and recognized on my log)

I hope someone would have some ideas

Thank you in advance

PS: I'm French, sorry for my English

Answered by DTS Engineer in 851958022

Thanks.

The weird thing about this is that you read the source file twice:

  • First you read it into tempData to check the prefix.
  • Then the copy engine reads the file so it can copy it.

The error you posted indicates that it’s the copy engine that’s failing; note how the error includes NSUserStringVariant with a value of Copy. So, either:

  • I’ve misunderstood your code.
  • The first read works but the second read, the one done by the copy engine, fails. That would be really strange.
  • This is nothing to do with the source file.

To rule out the first possibility, step through the copy and see which line actually throws the error.

To rule out the third possibility, step through the code to the point where it’s constructed destinationURL and then check that the path (except for the last item) exists.

In your example, the output file is:

/Users/
  jean-philippegreaux/
    Library/
      Containers/
        jgreaux.gestion-de-comptes/
          Data/
            Documents/
              2025/
                7/
                  justificatif_88.pdf

I suspect that 2025 or 7 is missing, and hence this error.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What specific error are you getting?

I can see a couple of potential issues here:

  • Sandboxed apps have to be careful when accessing files that are dropped on to them. That drop represents a dynamic extension to the sandbox (see On File System Permissions for an explanation of that). If you don’t handle the file correctly, you could run into a permissions error.
  • However, you mentioned “file not found”, which doesn’t sound like that, so it’s possible you’re hitting some other issue entirely.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Tanks for the answer,

The Logs from Xcode (on the Mac Book Air) are the following:

5 Reentrant message: kDragIPCWithinWindow, current message: kDragIPCWithinWindow ✅ PDF détecté ❌ Échec lors de la copie : Error Domain=NSCocoaErrorDomain Code=4 "Le fichier « brochure_nissan_eNV200_evalia-2.pdf » n’existe pas." UserInfo={NSSourceFilePathErrorKey=/Users/jean-philippegreaux/Downloads/brochure_nissan_eNV200_evalia-2.pdf, NSUserStringVariant=(     Copy ), NSDestinationFilePath=/Users/jean-philippegreaux/Library/Containers/jgreaux.gestion-de-comptes/Data/Documents/2025/7/justificatif_80.pdf, NSFilePath=/Users/jean-philippegreaux/Downloads/brochure_nissan_eNV200_evalia-2.pdf, NSURL=file:///Users/jean-philippegreaux/Downloads/brochure_nissan_eNV200_evalia-2.pdf, NSUnderlyingError=0x600002a8ab80 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} ❌ Échec du traitement du fichier 5 Reentrant message: kDragIPCCompleted, current message: kDragIPCLeaveApplication

ps: what's bothering me is that the issues is none existant on my MacMini

Thanks in advance

Thanks for the extra info. I see two errors here:

  • The top-level error is NSCocoaErrorDomain code 4, which is NSFileNoSuchFileError.
  • The underlying error is NSPOSIXErrorDomain code 2, which is ENOENT.

Cocoa errors can be a bit ‘squishy’, meaning that the same error can come from a variety different sources. However, the presence of the ENOENT error suggests that this really is a file not found problem of some form.

It looks like the source file is in the Downloads folder. That might be important because that folder is protected by MAC [1]. If you use the Finder to move the file to your home directory and then drag the file on to your app, does that work?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] That’s another topic I cover in On File System Permissions.

The error persists in the document folder and on the desktop. Here are the logs when droping from the document folder:

Unable to open mach-O at path: default.metallib  Error:2 ✅ PDF détecté ❌ Échec lors de la copie : Error Domain=NSCocoaErrorDomain Code=4 "Le fichier « Facture - Contrôle Technique - Land Rover Defender - 118V.pdf » n’existe pas." UserInfo={NSSourceFilePathErrorKey=/Users/jean-philippegreaux/Documents/Facture - Contrôle Technique - Land Rover Defender - 118V.pdf, NSUserStringVariant=(     Copy ), NSDestinationFilePath=/Users/jean-philippegreaux/Library/Containers/jgreaux.gestion-de-comptes/Data/Documents/2025/7/justificatif_89.pdf, NSFilePath=/Users/jean-philippegreaux/Documents/Facture - Contrôle Technique - Land Rover Defender - 118V.pdf, NSURL=file:///Users/jean-philippegreaux/Documents/Facture%20-%20Contro%CC%82le%20Technique%20-%20Land%20Rover%20Defender%20-%20118V.pdf, NSUnderlyingError=0x600001a37ed0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}} ❌ Échec du traitement du fichier 5 Reentrant message: kDragIPCCompleted, current message: kDragIPCLeaveApplication

I even try to change the file name to avoid special characters and nothing change.

Hope you have other ideas. Thanks

The error persists in the document folder and on the desktop.

Right. Both of those locations are protected by MAC. Can you try it from a location that’s not protected that way, for example, your home directory. That is:

  1. Use the Finder to drag your the document to the your home directory.
  2. Then drag the document from there to your app.

Does that change things?


Some other questions:

  • Are you dragging the document to your app icon? Or to a view within your app?
  • If it’s a view, what UI framework are you using? AppKit? SwiftUI?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Ok. I tried my user directory and the user directory. Same result:

❌ Échec lors de la copie : Error Domain=NSCocoaErrorDomain Code=4 "Le fichier « 2019-BMW-X2-Specs-Build-Sheet.pdf » n’existe pas." UserInfo={NSSourceFilePathErrorKey=/.nofollow/Users/2019-BMW-X2-Specs-Build-Sheet.pdf, NSUserStringVariant=(     Copy ), NSDestinationFilePath=/Users/jean-philippegreaux/Library/Containers/jgreaux.gestion-de-comptes/Data/Documents/2025/7/justificatif_88.pdf, NSFilePath=/.nofollow/Users/2019-BMW-X2-Specs-Build-Sheet.pdf, NSURL=file:///.nofollow/Users/2019-BMW-X2-Specs-Build-Sheet.pdf, NSUnderlyingError=0x600001ed9410 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

❌ Échec lors de la copie : Error Domain=NSCocoaErrorDomain Code=4 "Le fichier « 2019-BMW-X2-Specs-Build-Sheet.pdf » n’existe pas." UserInfo={NSSourceFilePathErrorKey=/Users/jean-philippegreaux/2019-BMW-X2-Specs-Build-Sheet.pdf, NSUserStringVariant=(     Copy ), NSDestinationFilePath=/Users/jean-philippegreaux/Library/Containers/jgreaux.gestion-de-comptes/Data/Documents/2025/7/justificatif_87.pdf, NSFilePath=/Users/jean-philippegreaux/2019-BMW-X2-Specs-Build-Sheet.pdf, NSURL=file:///Users/jean-philippegreaux/2019-BMW-X2-Specs-Build-Sheet.pdf, NSUnderlyingError=0x600001ecb4e0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

The drag and drop is on a swiftUI component VStack().onDrop() which is displayed in a .sheet()

Here is the function used in .onDrop()

func handleJustificatif(
        providers: [NSItemProvider],
        currentTransaction: Transaction,
        completion: @escaping (Bool) -> Void
    ) {
        guard let provider = providers.first,
              provider.hasItemConformingToTypeIdentifier(UTType.fileURL.identifier) else {
            print("❌ Aucun provider ou fichier PDF détecté")
            completion(false)
            return
        }

        provider.loadItem(forTypeIdentifier: UTType.fileURL.identifier, options: nil) { item, error in
            guard let data = item as? Data,
                  let fileURL = URL(dataRepresentation: data, relativeTo: nil) else {
                print("❌ Impossible d'extraire l'URL depuis l'item")
                completion(false)
                return
            }

            let accessGranted = fileURL.startAccessingSecurityScopedResource()
            defer {
                if accessGranted {
                    fileURL.stopAccessingSecurityScopedResource()
                }
            }

            do {
                let tempData = try Data(contentsOf: fileURL)
                let prefix = tempData.prefix(4)

                guard let prefixString = String(data: prefix, encoding: .ascii),
                      prefixString.hasPrefix("%PDF") else {
                    print("❌ Fichier non valide : taille \(tempData.count) — préfixe : \(prefix)")
                    completion(false)
                    return
                }

                print("✅ PDF détecté")

                let relativePath = currentTransaction.getAttachmentPath()
                let documentsURL = try FileManager.default.url(
                    for: .documentDirectory,
                    in: .userDomainMask,
                    appropriateFor: nil,
                    create: true
                )

                let destinationURL = documentsURL.appendingPathComponent(relativePath)

                if FileManager.default.fileExists(atPath: destinationURL.path) {
                    try FileManager.default.removeItem(at: destinationURL)
                }

                try FileManager.default.copyItem(at: fileURL, to: destinationURL)

                DispatchQueue.main.async {
                    currentTransaction.attachment = tempData.count
                    print("✅ PDF copié : \(destinationURL.lastPathComponent) (\(tempData.count) octets)")
                    completion(true)
                }

            } catch {
                print("❌ Échec lors de la copie : \(error)")
                completion(false)
            }
        }

Hope that help, Thanks again

Thanks.

The weird thing about this is that you read the source file twice:

  • First you read it into tempData to check the prefix.
  • Then the copy engine reads the file so it can copy it.

The error you posted indicates that it’s the copy engine that’s failing; note how the error includes NSUserStringVariant with a value of Copy. So, either:

  • I’ve misunderstood your code.
  • The first read works but the second read, the one done by the copy engine, fails. That would be really strange.
  • This is nothing to do with the source file.

To rule out the first possibility, step through the copy and see which line actually throws the error.

To rule out the third possibility, step through the code to the point where it’s constructed destinationURL and then check that the path (except for the last item) exists.

In your example, the output file is:

/Users/
  jean-philippegreaux/
    Library/
      Containers/
        jgreaux.gestion-de-comptes/
          Data/
            Documents/
              2025/
                7/
                  justificatif_88.pdf

I suspect that 2025 or 7 is missing, and hence this error.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Drop file not found on MacBook Air
 
 
Q