Paths | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429634-saving-data-in-ios/lessons/3

what is the difference between the Main Bundle and the documents directoryURL?

Hello, thank you for checking out the videos!

An excellent question. Here is Apple’s official description on bundles and the main bundle:

Apple uses bundles to represent apps, frameworks, plug-ins, and many other specific types of content.

The Bundle class has many constructors, but the one you use most often is main . The main bundle represents the bundle directory that contains the currently executing code. So for an app, the main bundle object gives you access to the resources that shipped with your app.

So in a regular iOS app, you create an app with resources like storyboards, fonts, images, audio files, etc. This is your main bundle that you have by default. You can also provide separate bundles that you perhaps include via a third-party framework, or to aid you in reusing resources across different projects.

The documents directory is a folder/directory that resides in your app’s sandbox, which is where your user data like documents, saved images, JSON files, databases, app data, etc., might live.

Bundles ship with your app and is where you often read and load user interface files from, images, etc, while the sandbox is available once you have installed the app on a device and is where the operating system tells you to save files and tinker with things in a safe space.

Since you can’t modify the app’s bundle, nor should you want to, and given Apple’s best-practices, you save files and resources to the documents directory within your app sandbox :slight_smile:

I hope that has helped clarify the difference a bit, if not please post any follow up questions and I’ll be happy to help :smiley:

Thanks again and happy coding!