I need to read/write a tiny amount of info for data persistence in an iOS app. I am using plists and understand that I can read, but not write to the bundle. If I create the plist files initially at development time, how can I place the plists in the "Documents" area of my app so that they are later writable?
Short answer: No.
As you say, an iOS app's bundle is not writable, but it is readable.
Further, an app's documents directory doesn't exist until the app is run (on the user's target device) for the first time. Thus, you can't build your app's documents directory at compile-time, nor can you submit an app to the app store with a prepopulated Documents directory. (It would be nice if Apple gave us the ability to provide a "seed" documents directory that got moved to the documents directory at first launch, but they do not provide that facility -- at least not that I'm aware of.)
What you can do is to create a sub-directory of your bundle that contains a set of files that you want to place in the app's documents directory.
On launch, check a "hasBeenInstalled" flag in UserDefaults
. If it's true, do nothing. if it's false, use the file manager to copy files from your app's bundle into the app's documents directory, then write hasBeenInstalled=true
to UserDefaults
.