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:
- 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.
- 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.
- Drag the compacted copy of your Realm file to your production app's Xcode Project Navigator.
- Go to your app target's Build Phases tab in Xcode. Add the Realm file to the Copy Bundle Resources build phase.
- 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
you want to modify the bundled realm, first copy the bundled file to
your app's Documents folder with
See the migration sample app for a complete working app that uses a bundled realm.