addPersistentStoreWithType fails

Does a core data database location have to be under the app's applicationDocumentsDirectory? That is how it is behaving for me.


I would like to create my core data database in a folder of my choosing; however, when I attempt to create it outside of the applicationDocumentsDirectory, it fails.


Works fine:

databaseURL path: Users/rickschlueter/Library/Containers/com.eBetsy.eBetsy/Data/Library/Application%20Support

[coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.storeDataURL options:options error:&error]

Fails:

databaseURL path : Users/rickschlueter/Pictures/Inventory%20Database

error: Error Domain=NSCocoaErrorDomain Code=512 "The file couldn’t be saved." UserInfo={reason=Failed to create file; code = 1}

Accepted Answer

Do you have sandboxing turned on for your application?

Have you checked what the permissions for those directories are?


Core Data doesn't impose any restrictions on where you can create the persistent stores. But OS X does, particularly if you opt in to the application sandbox (which is pretty much mandatory for App Store apps) instead of the old fashioned 'Do whatever you want' application model.

>when I attempt to create it outside of the applicationDocumentsDirectory, it fails.


How are you testing...what permissions - user or root or?

Yeah, that's it. I was going to sell this on the App Store, but am now just using it for my own company, so want to put the database on DropBox.

Turned off sandboxing and it is working now.

Thanks

addPersistentStoreWithType fails
 
 
Q