Where to save and access files in iOS Swift 3.0

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:

Caches Directory

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.

App Directory

SearchPathDirectory.applicationDirectory – App Directory is where to keep files the app uses to run but should be hidden from the user.

Document Directory

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.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>