1

I am using the following code to read the content of a text file.

let str = try! String(contentsOfFile:"/Users/my/Desktop/a.txt")

It works well until I upgraded my Xcode to 9.1 version and this line of code made the app crashed. The error is :

Error Domain=NSCocoaErrorDomain Code=257 "The file a.txt” couldn’t be opened because you don’t have permission to view it."

How can I get the permission to read the file?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
cococurry
  • 63
  • 3
  • If the app is sandboxed you have only access to the data in the container. But this behavior is not particularly related to Xcode 9.1 – vadian Jan 22 '18 at 07:26
  • You are right ! thanks a lot for your reminding, I checked the Capabilities of the Target, and the sandbox switch is on. – cococurry Jan 31 '18 at 11:00
  • Refer to this [answer](https://stackoverflow.com/a/50167291/6521116) with a good summary of this issue. – LF00 May 04 '18 at 05:24

0 Answers0