macOS Catalina + Xcode 11 Error on reading file from project

Viewed 2523

After upgrading to macOS Catalina with latest Xcode 11, I am not able to read files directly from user path when doing unit testing, example: PROJECT_DIR + "/FolderX/myFile.json", I keep getting error Thread 1: EXC_BAD_ACCESS (code=1, address=0x8)

This is also happened when I am trying to open a couchbase lite database with custom path. Error: error opening!: 14 Cannot open database, Error : Error Domain=SQLite Code=14 "unable to open database file" UserInfo={NSLocalizedDescription=unable to open database file}

I believe this is an issue due to the read write access between my simulator and the latest Catalina.

My current workaround is to add my files and database to target membership and read the files directly from [NSBundle bundleForClass:[self class]].bundlePath. Is there any better fix to this? Like tweaking any setting to allow it to read files from custom path like in older versions?

3 Answers

You might try looking in SystemPreferences > Security&Privacy > Privacy tab. From there, scroll down to "Files and Folders" <-- There's where you can see programs and the folders they have been granted access to in Catalina.

Personally, I didn't have time to waste figuring out how the new file permissions are supposed to work, so I let Xcode have full disk permission. (Right above the "files and folders" is "Full Disk Access".

Of course, that solved all my issues... after I get a chance to play with the new file permissions, I may revoke that access and give it explicit folder access.

Well if anyone is still struggling with this, I've moved all my projects outside of ~/Documents/

it is strange that projects under ~/Documents/ doesnt get asked for read permission, other paths do! I end up putting all my projects under ~/workspace/

** for those who doesnt know, ~/ means /Users/{your username}/

Check your File Access settings in the App Sandbox in your project's settings, under Signing and Capabilities. For example, I couldn't access files in /Users/Bert/Downloads, even after turning on Full Disk Access in Security and Privacy in System Preferences. I had to grant read access to the Downloads Folder in App Sandbox settings.

Screenshot of Project Settings

Related