Post

Replies

Boosts

Views

Activity

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update
There is something that I'm spending hours trying to solve but start to be blocked. On one of my app projects, I'm experiencing random fatal errors during the access and update of SwiftData Models, which does not occur when using CoreData. This mainly happens when setting value for newly created entities: SwiftData randomly crashes the application with the following error: EXC_BAD_ACCESS (code=1, address=0x11). I made sure to update the code to move operations in the background and to use a ModelActor. It works properly, but 1 out of 3 times, it crashes with the error quoted. I also tried to look at previous posts and made sure to persist the context when creating new entities, before updating them. The last information in my console before “(lldb)” is: CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](2996): <NSCloudKitMirroringDelegate: 0x2806342a0>: Observed context save: <NSPersistentStoreCoordinator: 0x281434c40> - <NSManagedObjectContext: 0x280450820> CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate remoteStoreDidChange:](3039): <NSCloudKitMirroringDelegate: 0x2806342a0>: Observed remote store notification: <NSPersistentStoreCoordinator: 0x281434c40> - FF2D0015-7121-4C30-9EE3-2A51A76C303B - <NSPersistentHistoryToken - { "FF2D0015-7121-4C30-9EE3-2A51A76C303B" = 1316; }> - file:///private/var/mobile/Containers/Shared/AppGroup/ED0B229A-F5BC-47B7-B7BC-88EEFB6E6CA8/Library/Application%20Support/default.store CoreData: debug: CoreData+CloudKit: -[NSCloudKitMirroringDelegate managedObjectContextSaved:](2996): <NSCloudKitMirroringDelegate: 0x2806342a0>: Observed context save: <NSPersistentStoreCoordinator: 0x281434c40> - <NSManagedObjectContext: 0x280450820>. In the rare occasion where it provides more details, Xcode shows issue in the @Model macro, as shown in the screenshot attached. I was able to reproduce this issue on 4 different physical devices and in the simulator. It also happens, less frequently, when trying to fetch a Model entity from the SwiftData context. Not for specific models tho, it can happen for all of them, randomly. I was able to experience this random problem both on iOS 17.0 Developer Beta, RC & the official iOS 17.0 release. At the time in the beta Xcode 15, and now the latest stable Xcode. Am I the only one having this kind of issues? Or is it a known issue with Swift? Anybody has idea how I could solve that?
5
2
2.9k
Sep ’23