ios - How to load thousands records to Realm correctly? -


i'm trying save 8000 records disk, using realm, it's blocking ui. result, use realm.asyncopen performs data saving in background thread.

the problem 100% cpu usage when try save big amount of records manner.

how load thousands records realm correctly?

try way in official demo save large amounts of data:

dispatchqueue(label: "background").async {   autoreleasepool {     // realm , table instances thread     let realm = try! realm()      // break writing blocks smaller portions     // starting new transaction     idx1 in 0..<1000 {       realm.beginwrite()        // add row via dictionary. property order ignored.       idx2 in 0..<1000 {         realm.create(person.self, value: [           "name": "\(idx1)",           "birthdate": date(timeintervalsince1970: timeinterval(idx2))         ])       }        // commit write transaction       // make data available other threads       try! realm.commitwrite()     }   } } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -