- Clear the database.
- Create an API call to retrieve new data.
- Write the data received from the API to the database in the background thread.
- Reading data from a database in the main stream and displaying the user interface.
In step 4, the data should contain the most recent data, but we do not see any data.
// remark: all main thread shared a realm object DBManager.deleteAll() // call api success, get newdata DispatchQueue.global(qos: .background).async { DBManager.initDBData(<newdata>) DispatchQueue.main.async { print("has data?????", DBManager.getBrands().count) } } // when write func write() { let realmBackgroud = try! Realm() try! realmBackgroud.write {} }
source share