How can I keep the data on realm consistently?


I’ve ran iPhone7 on simulator and added about 100 “name” on the data by ream browser locally
but when I open iphone6 for example I found 0 “name”??
is that means if I uploaded the app to App Store will show no data?


What did you do? You just put it 100 data in a local realm?
It won’t be synced if you are don’t copy them to a synced realm.


Yep!! I thought it’s like sql and plist I am about to cry
How to synced realm please?


Its like sql…
Read the docs about the synced realm. you can find it here:


but in this case it should be online? no way for offline !
it’s my first app


No. The synced realm is the realm cloud version, where the user data sync to the server.
You can have default data in the cloud and every user can access to that. If you cange something, then that will be synced to the clients too.

I highly recommend to check out the documentation and how other using realm. There are some non-trivial things that can ease your life :slight_smile:


The question is a bit vague: Are you intending the data to be stored locally on the device (for just this users consumption) or stored in Realm Cloud where it can be accessed by multiple devices?

If it’s stored locally then you will not need any kind of ‘sync’ing’ as the data is stored in the device. If you want to store the data ‘in the cloud’ then you would need to set up the app for either a query based or fully synchronized Realm (i.e. Realm Cloud)


Yes, it’s just for this users locally … and no changes will be made later!
So I need when someone open the app on his device to find the data I left whatever he has iphone7 or iPhonex


You can check the docs for instructions on how to bundle a Realm file with your app.


That’s it the right title thank you, but it’s actually still hard to understand and execute for me


Hard to understand and execute is quite generic and I’m not sure I can help you unless you are more specific about what’s hard. Did you try following the steps outlined in the docs? If so, which step is blocking you right now?


Thank you again, I tried to copy a chunk of code to bundle it from stackoverflow but nothing is working like these below after I copied the realm data to documents

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        openRealm() //2
        print(Realm.Configuration.defaultConfiguration.fileURL) //3
        return true
    func openRealm() {
        let bundlePath = Bundle.main.path(forResource: "default", ofType: "realm")
        let defaultPath = Realm.Configuration.defaultConfiguration.fileURL!.path
        let fileManager = FileManager.default
        // Only need to copy the prepopulated `.realm` file if it doesn't exist yet
        if !fileManager.fileExists(atPath: defaultPath){
            print("use pre-populated database")
            do {
                try fileManager.copyItem(atPath: bundlePath, toPath: defaultPath)
            } catch {
    } //f

and if I have to do any changes to ViewController after this?


problem solved, I forget to target membership on the file however if someone know a better way/code to execute this on swift 4.2 I’ll be happy to hear. Thanks everyone for helping specially this good man @nirinchev