I'm new to iOS development. I've created an app in SwiftUI that fetches data from firebase and saves it coredata. I've used Task{}, async and await for my JSON conversions, coredata fetch/save, etc.
The app is working fine and has been uploaded to app store too. Only in some devices with memory issues, the performance degrades. Though the app doesn't crash at any time in any devices, the UI blocks for a fraction of second while some data is being processed.
After a few hours of research regarding background threads, concurrency, managed objects, etc., I found it's not a good practice to use the viewContext for all the purposes.
So, here is why this happens: All the changes, fetch requests, batchdelete etc, are performed on the viewContect from the persistanceController. This file is auto generated by xcode while creating the project.
We need to use different context for saving and reading. We need to perform the CPU intensive operations in a background thread.
I did NOT find any codelabs/tutorials concerning coredata. The apple document explains building coredata stack etc with appDelegate, controller etc kinds of files which are not SwiftUI related.
Being new to iOS, I've learnt only SwiftUI and not the others. Please provide any links or documentation for recommended/best practices for coredata in SwiftUI.