Unable to get file handle when running code within Xcode

Hi All,

I have the following code in swift to read and print a file's content:

Code Block
import Foundation
let a = try String(contentsOfFile: "/Users/humza/Desktop/test.txt")
print(a)


I am able to run the code in an Xcode playground.

However, when I make a command line project in Xcode 11.4.1, I get the following error when running the project:


Fatal error: Error raised at top level: Error Domain=NSCocoaErrorDomain Code=257 "The file “test.txt” couldn’t be opened because you don’t have permission to view it."

Note the build is successful and I can run the executable from terminal.

What is preventing this from running within Xcode?

I do not have a sandboxing capability added to my project. I have tried clearing the project's build folder. I have also given Xcode full disk access. I have also given my file full 777 permissions to help debug.




Unable to get file handle when running code within Xcode
 
 
Q