Accessing The App Documents folder, The Swift Way

ios_app_layout_2xWhen you create a new iOS application on your Mac, the operating system installs it in a sandbox directory, which contains the application bundle directory and three additional directories, Documents, Library, and tmp. The application’s sandbox directory, often referred to as the home directory, can be accessed via code or Finder.

By the way, the OS used to create the application sandbox in this directory, on your Mac’s hard drive:

~/Library/Application/iPhone Simulator

Now, it is created in this directory:


Accessing The App Documents Folder Via Code

Now, to retrieve and display the full path to an application’s Documents directory, you’d have to add this code snippet in a Swift file’s function; for example, the viewDidLoad() function.

let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray
let documentsDir = paths.firstObject as String
println("Path to the Documents directory\n\(documentsDir)")
Code Output
Path to the Documents directory
Accessing The App Documents Folder Via Finder

Now that you’ve gotten the full path to the application’s Documents folder. You can use Finder’s menu (Go > Goto Folder…) to navigate to that path. You’ll have to enter the path in Finder’s Goto Folder box like this:


Once you click the Go button, Finder will take you straight to the application’s Documents folder.


That’s it. Now you know two ways to access your iOS application’s Documents folder.