Search code examples
iosswiftrealmios-app-group

Is it good approach to keep database in AppGroup's shared container


I am using Realm in my application as database and i am having share extension to support media to be share from other application. Since i need my database to be accessed from share extension i moved realm file from App's document directory to Appgroup's shared container. I have below questions.

  1. Is it safe to store the database in shared container space.
  2. When i uninstall the app, still files inside shared container persist, so when the shared container will be deleted.
  3. Any other best practices to handle my scenario.

Solution

  • It appears that you cross-posted this in Realm's GitHub issue tracker. My comment from https://github.com/realm/realm-cocoa/issues/4899#issuecomment-297121059 reposted here for your convenience:

    1. Is it safe to store the database in shared container space.

    Yes. In fact it's the only way to share files across processes on iOS.

    1. When i uninstall the app, still files inside shared container persist, so when the shared container will be deleted.

    According to https://stackoverflow.com/a/25027088/373262, iOS deletes shared containers once the last app to have access to it is removed from the device.

    If you find situations in which this doesn't happen, I encourage you to file a radar to inform Apple about the bug. https://bugreport.apple.com

    1. Any other best practices to handle my scenario.

    Sounds like you're doing everything right. Keep it up! 👌


    In the future, please don't cross-post questions on StackOverflow with the realm tag as well as Realm's GitHub repos. The Realm engineering team monitors both of these channels, so your question will be answered even if you just post it once.