Realm data Insertion took over 7mins for big size json
insertUserData
method method opens transactions so many times in the loop. To commit transaction is a little bit expensive operation.
Can you try to put out to open/commit a transaction outside of the loop?
In other words, open the transaction before entering the loop, and commits the transaction once after the end of the loop. Like the following:
if results.count > 0 {
if let users = results.array {
let realm = try! Realm()
try realm.write {
for user in users{
let userList=UserList()
userList.start=user["Start”].stringValue
userList.end=user[“End”].stringValue
userList.name=user[“Name”].stringValue
userList.address =user[“Address”].stringValue
realm.add(userList,update: true)
}
}
}
}
Maximum call stack size exceeded error
It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.
This is almost always because of a recursive function with a base case that isn't being met.
Viewing the stack
Consider this code...
(function a() {
a();
})();
Here is the stack after a handful of calls...
As you can see, the call stack grows until it hits a limit: the browser hardcoded stack size or memory exhaustion.
In order to fix it, ensure that your recursive function has a base case which is able to be met...
(function a(x) {
// The following condition
// is the base case.
if ( ! x) {
return;
}
a(--x);
})(10);
Android - Storing 'large' data locally
The SQLite is binary format that is relatively fast.
Use SQLite or Realm. Imho, Realm (based on SQLite) engine might be better in your case (it faster that pure SQLite).
Realm vs Sqlite for mobile development
Nowadays there is a Firebase Database from Google. Imho, you can you this format too because of it has both server and offline interactions. Because of both SQLite formats must be stored in APK file. But in order to work inside the application it is needed that sqlite-file have to be copied from assets (or raw) directory into database (workable) directory. That's why all data would be dublicated(!). Firebase Database do not have this disadvantage.
https://firebase.google.com/docs/database/android/start/
JSON and XML formats are too huge (and memory and machine time consumed) to work with them.
Oh. forgot! it is possible to integrate your code directly inside the code. Just create a class to work:)
Related Topics
Avplayer Won't Let Me Access Url
How to Get a Popup Dialog Box in Swift Playgrounds
Prevent Nscollectionview 'Lifting' an Item During Drag
Wkwebview - Update HTML Tags from Swiftui Textfields
Uialertview or UIalertcontroller to Display Only Once in Swift
Wkwebview Problems in Macos Mojave
Swiftui Conditional View Transitions Are Not Working
Back to Table View from Detail Page Without Reload, Swift
Close Window Based on Kcgwindowname Value
Preload a Scene to Prevent Lag
Why Is a Firestore Listener Returning .Added Twice When a Single Document Is Added
Why Do I Keep Getting The Error "No Such Module 'Realmswift'"
How to Keep Nsmenuitem Selected in a Nspopover with Nsmenu
Uinavigationbar Turns White and Won't Close When Using Navigationitem.Searchcontroller in iOS 13
How to Highlight a Custom UIbutton That Has No Text or Background
Swift Use 'Is' for Function Type, Compiler Behavior Is Different with Runtime
Nstimer() - Timer.Invalidate Not Working on a Simple Stopwatch