Xcode custom working directory ignored

It appears that macOS applications are ignoring the current working directory set by Xcode. Here is a simple Xcode project that demonstrates the problem: https://www.ultraengine.com/downloads/xcodeworkingdir.zip

The application starting directory retrieved by NSFileManager:currentDirectoryPath is always "/Users/josh/Library/Containers/whatever.test/Data" even though in the product schema I have a custom working directory set to $(PROJECT_DIR).

Tested on macOS Catalina with Xcode 12.2 and 11.3.1.

Post not yet marked as solved Up vote post of MichaelKlint Down vote post of MichaelKlint
814 views
  • If I change the current directory using either NSFileManager:changeCurrentDirectoryPath or _wchdir, both functions succeed, but a following call to get the current directory fails. If getcwd is used, it produces errno 1 (operation not permitted), and NFFileManager.currentDicrectoryPath is equal to nil.

    The Xcode project location is in a subfolder of the user Documents directory.

  • I enabled full disk access to the application in the security and privacy system settings, but it seems to make no difference.

  • Additionally, I have observed that fopen fails to read a file in the target directory. To me, this indicates some security feature may be blocking the program from accessing the hard drive, even though I have full disk access enabled for this application.