July 11th, 2018
I ran into an issue with a new document-based Cocoa app throwing exceptions when I tried to save the document. It turns out the issue was the App Sandbox, which is turned on when you create a new Cocoa application project in Xcode.
You can see the App Sandbox settings by selecting your project from the project navigator to open the project editor. Select your target and click the Capabilities button at the top of the editor. The following screenshot shows the initial settings:
Notice that the App Sandbox initially doesn’t give your app access to anything. It won’t let you print or make any network connections. Surprisingly the App Sandbox does not initially give you permission to open a Save panel to let someone choose where to save a document on their Mac. Apparently opening a Save panel is insecure. Access to user selected files is read only initially. To allow a Save panel to open, you must change the permission for user selected files to Read/Write.
If Xcode is throwing exceptions when your Cocoa app does simple things like print, open a Save panel, or show a website in a web view, it might not be a problem in your code. It might be the App Sandbox.
There are two ways to work around the App Sandbox. The first workaround is to turn off the App Sandbox. The second workaround is to give your app permission to do things like print and display web content in the App Sandbox.