Post

Replies

Boosts

Views

Activity

Reply to Swift UI + Core Data in a background thread?
As you have discovered, you cannot ignore the threading requirements of CoreData or SwiftUI. If you retrieve objects in a background context/thread, you cannot access them in the main thread (ie SwiftUI). How many FRCs are you instantiating? Can you do updates with one set of FRCs in background contexts, and then use another set in the viewContext? Have you tried setting the batching levels on your FRCs?
Jun ’23
Reply to Core Data and FetchedResultsController bugged behaviour after application crash (or forced exit)
this code is losing the managed object context: func performInBackground(operation: BackgroundOperation) { container.performBackgroundTask { context in self.backgroundQueue.async { operation.execute(context: context) } } } you don't need backgroundQueue. it should be this instead… func performInBackground(operation: BackgroundOperation) { container.performBackgroundTask { context in operation.execute(context: context) } }
May ’23
Reply to Items are not updated on UI after updating them in Core Data
fwiw, I still can't see enough of your code to determine the issue, but… One reason that your code may not be seeing changes is that all three views are probably using the same view (main thread managed object) context, and you're saving changes on that same context, so there's no signaling that changes are being made. If you're going to invest time into Core Data, I highly recommend mastering NSFetchedResultsControllers and using background contexts to change data (adds, edits, deletes). I even wrote an article about it! Hope it helps. https://medium.com/@deeje/practical-ios-architecture-coredata-cloudkit-lists-and-editors-638c87d382d3
Mar ’23
Reply to How can I conform NSSecureCoding in my Core Data entity class
The fundamental challenge with using Codable with Core Data entities is that, when you instantiate an entity, it must be within a current managed object context (and its thread). I have seen lots of articles written by others who tackled the challenge. e.g. https://medium.com/swlh/core-data-using-codable-68660dfb5ce8 https://medium.com/@andrea.prearo/working-with-codable-and-core-data-83983e77198e https://www.hackingwithswift.com/forums/100-days-of-swiftui/day-61-my-solution-to-make-core-data-conform-to-codable/2434
Feb ’23
Reply to SwiftUI: Performance problems List of TextField
The stuttering is likely the allocation of new TextViews. fwiw, SwiftUI is still rather new compared to UIKit. UIKit includes TableView and CollectionView, which are designed to display, and scroll thru, large lists and grids of lots of things very efficiently. It does this by re-using a limited pool of "cell" views. SwiftUI currently does not expose this. It does have LazyH and LazyV, which means that the lazy views aren't instantiated until they are displayed, but they are not re-used.
Feb ’23