Bundle a Realm File with Your App - iOS SDK

You might want to seed your app with some initial data that is available to users on first launch. To do so, you can bundle a Realm file with your app:

  1. Create a new project with the exact same data models as your production app. Open a realm and add the data you wish to bundle. Since Realm files are cross-platform, you can do this in a macOS app.
  2. Make a compacted copy of the file. This reduces the Realm file size, which makes your app lighter to download. See Make a Compacted Copy.
  3. Drag the compacted copy of your Realm file to your production app's Xcode Project Navigator.
  4. Go to your app target's Build Phases tab in Xcode. Add the Realm file to the Copy Bundle Resources build phase.
  5. At this point, your app can access the bundled Realm file. Find its path with NSBundle.main.path(forResource:ofType).

You can open the realm at the bundle path directly if the readOnly property is set to true on the Realm.Configuration. If you want to modify the bundled realm, first copy the bundled file to your app's Documents folder with NSFileManager.default.copyItem(at:to:).


See the migration sample app for a complete working app that uses a bundled realm.

Give Feedback