2

I am writing an app which uses CoreData using NSPersistentContainer to save data.

While I am developing the app, I would like to:

  • examine the data directly
  • back up the data
  • see what happens when I change the bundle id

I assume the data is physically stored somewhere, but I’m not sure where to look.

Manngo
  • 14,066
  • 10
  • 88
  • 110

1 Answers1

2

By default NSPersistentContainer stores the database inside app container under directory Libray/Application Support

enter image description here

To locate the full path, in simulator, you can print the applicationSupportDirectory using urls(for:in:) function of the default FileManager:

print(FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first?.path ?? "nil")

If you are running your app on an actual device you can download the application container following this answer.

For sandboxed apps the location goes like this:

~/Library/Containers/…/Data/Library/Application Support/…
gcharita
  • 7,729
  • 3
  • 20
  • 37
  • Does it make any difference if the application is sandboxed? I can’t find the file in that location. – Manngo Sep 15 '20 at 08:13
  • Are you running the app in simulator or on an device? – gcharita Sep 15 '20 at 08:14
  • On the device itself. – Manngo Sep 15 '20 at 08:14
  • @Manngo you can follow the steps that you can find in [this](https://stackoverflow.com/a/6121649/6791677) answer to download the application container from the device. – gcharita Sep 15 '20 at 08:19
  • 1
    OK, I found it in `~/Library/Containers/…/Data/Library/Application Support/…`. If you would like to add that for sandboxed apps, I can happily accept your answer. Thanks. – Manngo Sep 15 '20 at 09:02
  • @Manngo I updated my answer. [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers) – gcharita Sep 15 '20 at 09:06