N
N
Nikita2019-07-10 15:55:09
iOS
Nikita, 2019-07-10 15:55:09

Why are objects not saved in the Realm database?

I receive data from the server and immediately write it to the database (asynchronously):

//В теле Alamofire.request()
autoreleasepool{
                  let db = try! Realm()
                  db.autorefresh = true
                  let myObject = MyObject()
                   myObject.cloneFromAnotherObject(cur)
                    myObject.lang = myObjectServ.lang.lowercased()

                    try! db.write {
                        db.add(myObject)
                    }
                    db.refresh()
}

After that, if I restart the application and try to take this object from the database, I get a completely empty object without data (that is, all fields are equal to the standard values ​​specified during initialization). At the same time, if you use the application without restarting, all data is saved. What am I doing wrong? Realms configuration:
let configuration = Realm.Configuration(
            schemaVersion: 3,
            deleteRealmIfMigrationNeeded: true)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2019-07-13
@snitron

I did not find a solution to the problem and switched to using Core Data.

B
briahas, 2019-07-10
@briahas

and if deleteRealmIfMigrationNeeded: true make it false?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question