vrao
vrao

Reputation: 655

ios app crashes intermittently on core data entities - Multiple NSEntityDescriptions claim the NSManagedObject subclass

The ios app works when hooked to a mac and run in debug mode, sometimes it fails. When I clean and rebuild it works for sometime and then fails again. Also if I start the app sometimes it works, sometimes it crashes, as if something is happening in the background. Background notifications work when I click on them. I had three coredata models due to migration: GreenSynapse GreenSynapse 2 and GreenSynapse 3. I deleted two models: GreenSynapse GreenSynapse 2. GreenSynapse 3 name changes its name to GreenSynapse in Xcode explorer. Found in the filepath only one model GreenSynapse 3.xcdatamodel exists (see attached screenshot) Xcode InspectorHowever in Xcode project navigator it is displayed as GreenSynapse (without 3). The errors from debug gives errors on only few core data entities: Location, Contact, ConfigProfile and repeats on those very same entities whenever it crashes. But when I clean rebuild couple times, the error is gone. But comes back after some time. I do have more than 40 entities and it does not give error on them. I do have valid developer's license Here is the error:

warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'GreenSynapse.Location' so +entity is unable to disambiguate. CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'GreenSynapse.Location' so +entity is unable to disambiguate. warning: 'Location' (0x301c494a0) from NSManagedObjectModel (0x300868f50) claims 'GreenSynapse.Location'. CoreData: warning: 'Location' (0x301c494a0) from NSManagedObjectModel (0x300868f50) claims 'GreenSynapse.Location'. warning: 'Location' (0x301c6bf40) from NSManagedObjectModel (0x3008d0b90) claims 'GreenSynapse.Location'. CoreData: warning: 'Location' (0x301c6bf40) from NSManagedObjectModel (0x3008d0b90) claims 'GreenSynapse.Location'. warning: 'Location' (0x301c7f650) from NSManagedObjectModel (0x3008d2350) claims 'GreenSynapse.Location'. CoreData: warning: 'Location' (0x301c7f650) from NSManagedObjectModel (0x3008d2350) claims 'GreenSynapse.Location'. error: +[GreenSynapse.Location entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass CoreData: error: +[GreenSynapse.Location entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'GreenSynapse.Contact' so +entity is unable to disambiguate. CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'GreenSynapse.Contact' so +entity is unable to disambiguate. warning: 'Contact' (0x301c48790) from NSManagedObjectModel (0x300868f50) claims 'GreenSynapse.Contact'. CoreData: warning: 'Contact' (0x301c48790) from NSManagedObjectModel (0x300868f50) claims 'GreenSynapse.Contact'. warning: 'Contact' (0x301c6f7b0) from NSManagedObjectModel (0x3008d0b90) claims 'GreenSynapse.Contact'. CoreData: warning: 'Contact' (0x301c6f7b0) from NSManagedObjectModel (0x3008d0b90) claims 'GreenSynapse.Contact'. warning: 'Contact' (0x301c7e940) from NSManagedObjectModel (0x3008d2350) claims 'GreenSynapse.Contact'. CoreData: warning: 'Contact' (0x301c7e940) from NSManagedObjectModel (0x3008d2350) claims 'GreenSynapse.Contact'. error: +[GreenSynapse.Contact entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass CoreData: error: +[GreenSynapse.Contact entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'GreenSynapse.ConfigProfile' so +entity is unable to disambiguate. CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'GreenSynapse.ConfigProfile' so +entity is unable to disambiguate. warning: 'ConfigProfile' (0x301c486e0) from NSManagedObjectModel (0x300868f50) claims 'GreenSynapse.ConfigProfile'. CoreData: warning: 'ConfigProfile' (0x301c486e0) from NSManagedObjectModel (0x300868f50) claims 'GreenSynapse.ConfigProfile'. warning: 'ConfigProfile' (0x301c6f9c0) from NSManagedObjectModel (0x3008d0b90) claims 'GreenSynapse.ConfigProfile'. CoreData: warning: 'ConfigProfile' (0x301c6f9c0) from NSManagedObjectModel (0x3008d0b90) claims 'GreenSynapse.ConfigProfile'. warning: 'ConfigProfile' (0x301c7e890) from NSManagedObjectModel (0x3008d2350) claims 'GreenSynapse.ConfigProfile'. CoreData: warning: 'ConfigProfile' (0x301c7e890) from NSManagedObjectModel (0x3008d2350) claims 'GreenSynapse.ConfigProfile'. error: +[GreenSynapse.ConfigProfile entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass CoreData: error: +[GreenSynapse.ConfigProfile entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'executeFetchRequest:error: A fetch request must have an entity.' *** First throw call stack: (0x19125e5fc 0x18e7d9244 0x199241920 0x199261930 0x19925ca7c 0x1992afd88 0x1992ae75c 0x1992ae368 0x195aef7e8 0x195aef6e8 0x195aef69c 0x105ab9a1c 0x253fe2f1c 0x253fe2ca0 0x253fe2b94 0x105ab97d0 0x1959e5478 0x105870f4c 0x105ab9640 0x253fe2f1c 0x253fe2ca0 0x253fe2b94 0x105ab8eec 0x253fe2de8 0x253fe2ca0 0x253fe2b2c 0x105ab7840 0x1959af840 0x105ab7364 0x105ac83c4 0x253fb18a0 0x253fb12e8 0x253fb05a4 0x253fb01f4 0x1be04ccac 0x1be04c870 0x1be04c444 0x253fcc5a8 0x195987c84 0x253fcbfa8 0x253fcbd6c 0x253fcbce8 0x1959ab688 0x1959ab5d4 0x253fc5720 0x253fc56a4 0x195a09808 0x195a0976c 0x195a09698 0x195a095e0 0x193af0710 0x193af3040 0x193af0c5c 0x1912a4f4c 0x1912a4ee0 0x1912a7ba4 0x1912a6d3c 0x1912f9284 0x1de5654c0 0x193e42674 0x193a68e88 0x195bfeef8 0x195bfee28 0x195bfed0c 0x105cdc148 0x105cdc5e8 0x1b7551de8) libc++abi: terminating due to uncaught exception of type NSException

PersistenceController code:

class PersistenceController: ObservableObject {
// Singleton instance
static let shared = PersistenceController()

@Published var isSyncing = false
@Published var lastSyncError: Error?
@Published var isCloudKitAvailable = false

// Preview instance for SwiftUI previews
static var preview: PersistenceController = {
    let result = PersistenceController(inMemory: true)
    let viewContext = result.container.viewContext
    
    // Add preview data here if needed
    do {
        try viewContext.save()
    } catch {
        let nsError = error as NSError
        fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
    }
    return result
}()

let container: NSPersistentCloudKitContainer

{
    container = NSPersistentCloudKitContainer(name: "GreenSynapse")
    
    // Check CloudKit availability early
    checkCloudKitAvailability()
    
    // Setup CloudKit container
    let cloudKitContainer = CKContainer(identifier: "iCloud.com.abc.SynapseKit")
    
    // Configure store description
    if inMemory {
        container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
    }
    
    guard let description = container.persistentStoreDescriptions.first else {
        fatalError("Failed to retrieve persistent store description.")
    }
    
    // Enable automatic migration
    description.setOption(true as NSNumber, forKey: NSMigratePersistentStoresAutomaticallyOption)
    description.setOption(true as NSNumber, forKey: NSInferMappingModelAutomaticallyOption)
    
    // Configure CloudKit
    description.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(
        containerIdentifier: "iCloud.com.abc.SynapseKit"
    )
    
    // Setup remote change notifications
    setupRemoteChangeNotifications()
    
    // Configure sync strategy
    configureSynchronizationStrategy(for: description)
    
    // Load stores
    container.loadPersistentStores { [weak self] (storeDescription, error) in
        if let error = error as NSError? {
            print(" Persistent store load error: \(error), \(error.userInfo)")
            self?.lastSyncError = error
            
            #if DEBUG
            fatalError("Unresolved error \(error), \(error.userInfo)")
            #else
            print("Core Data store could not be loaded. Please contact support.")
            #endif
        } else {
            print(" Loaded store: \(storeDescription.url?.absoluteString ?? "No URL")")
        }
    }
    
    // Configure view context
    container.viewContext.automaticallyMergesChangesFromParent = true
    container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
    
    // Setup transaction author
    container.viewContext.transactionAuthor = "app"
    
    // Setup CloudKit sync monitoring
    setupCloudKitSyncMonitoring()
}

//other code 
}

It shows three times that sqlite is loaded - why? Loaded store: file:///var/mobile/Containers/Data/Application/13D32DF7-9744-4DB8-8B47-2F156B4B2CEC/Library/Application%20Support/GreenSynapse.sqlite. Loaded store: file:///var/mobile/Containers/Data/Application/13D32DF7-9744-4DB8-8B47-2F156B4B2CEC/Library/Application%20Support/GreenSynapse.sqlite. Loaded store: file:///var/mobile/Containers/Data/Application/13D32DF7-9744-4DB8-8B47-2F156B4B2CEC/Library/Application%20Support/GreenSynapse.sqlite.

Upvotes: 0

Views: 30

Answers (0)

Related Questions