Today I wasted a bit of time trying to write to a file. I didn’t realize the file directory that I was writing to was different than the directory I was reading from. Don’t do that!
So when you’re accessessing, reading or writing to files here are some of the different places to do so:
SearchPathDirectory.cachesDirectory is where you want to store temporary data that the app doesn’t need and could be deleted by the OS if it needs the space. The tmp directory, on the other hand will only keep files while the app is in the foreground.
SearchPathDirectory.applicationDirectory – App Directory is where to keep files the app uses to run but should be hidden from the user.
SearchPathDirectory.documentDirectory – This is the one I’ve used where information will persist between app loads, will be backed up by default, and that are exposed to the user – the user may write, read, delete, etc from.