Opening Realm: how prevent asyncOpen for a query based sync to load all data of all classes?


In Realm Sync Documentation (, I read:

We also recommend using synchronous open for all large data sets that are not contingent on the functioning of the app. For instance, in a retail app, you may want to asyncOpen the types of products, the locations of stores, and other business logic data, but the actual inventory of clothing should be synchronously downloaded in the background by the Realm process while the UI updates continuously.

Given the example above, I have a query based synced realm for a retail app with classes with small data sets like types of products, locations of stores, which I want to make available with all its contents right from the app start using asyncOpen. And then, I have classes with big data sets, like inventory, which I only want to load on demand (synchronously).

Given, all these classes live in the same realm (because they are in relationships), how can I tell asyncOpen which classes to load?


You’ll need to use query-based sync to each class of data. Use callbacks from each sync query to update the UI as new information comes in. Async or synchronous open makes no difference as far as syncing data from the server: both will sync no objects until you create the subscriptions.


So, executing this code doesn’t load any data?

let config = user.configuration(realmURL: realmURL))
Realm.asyncOpen(configuration: config) { realm, error in
    if let realm = realm {
        // Realm successfully opened, with all remote data available
    } else if let error = error {
        // Handle error that occurred while opening or downloading the contents of the Realm


Not any of your product types, stores, or inventory, no.

By default, a query-based synchronized Realm contains no data. Instead, the client application must choose, or subscribe to, which subset of data in the corresponding Realm on the server it wants to synchronize.