I have a weird bug that happens only on my M1 Mac mini when buiding for the simulator.
It is the typical table view NSInternalInconsistencyException error:
Code Block *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 2 into section 0, but there are only 2 rows in section 0 after the update'
The error is related to a table view instantiated and managed by SwiftUI so I have no control over datasources.
The corresponding View has a list fed a fetched result, with this property:
Code Block var recipes: FetchedResults<Recipe> { fetchRequest.wrappedValue }
The crash happens the I add an object to the NSManagedObjectContext that stores the app contents. It happens when performing a very simple and fundamental flow of my app (a recipes app: the action is "add a recipe", imagine that).
I found the crash yesterday after moving the project to my new M1 Mac.
I verified that there is no crash or warning on the device iPhone XR) or on my older 2018 MacBook Pro.
Anyone with a suggestion, or similar bugs?
Thanks,
Davide
The same error unluckily started happening also on devices.
Fortunately I found a workaround, at the end of this thread:
https://developer.apple.com/forums/thread/129956?answerId=409430022#409430022.
I wapped the model-updating code into
DispatchQueue.main.async { }
It must be a swift UI bug, but pushing these operations to the main thread seems to work. Davide