0

i crated a coredate in my project (Swiftui) i change the Attributes typa and now it make to me error when i save the data. it save the data but i cannot deleted..

From Debager:

2022-11-16 19:25:28.582162+0200 TorLight[14396:306398] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'HistoryList' so +entity is unable to disambiguate.
CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'HistoryList' so +entity is unable to disambiguate.
2022-11-16 19:25:28.582325+0200 TorLight[14396:306398] [error] warning:      'HistoryList' (0x600001d54fd0) from NSManagedObjectModel (0x600000974500) claims 'HistoryList'.
CoreData: warning:       'HistoryList' (0x600001d54fd0) from NSManagedObjectModel (0x600000974500) claims 'HistoryList'.
2022-11-16 19:25:28.582409+0200 TorLight[14396:306398] [error] warning:      'HistoryList' (0x600001d5c580) from NSManagedObjectModel (0x6000009619f0) claims 'HistoryList'.
CoreData: warning:       'HistoryList' (0x600001d5c580) from NSManagedObjectModel (0x6000009619f0) claims 'HistoryList'.
2022-11-16 19:25:28.582484+0200 TorLight[14396:306398] [error] error: +[HistoryList entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
CoreData: error: +[HistoryList entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass

Codegen in HistoryModel is Manual:

extension HistoryList {

    @nonobjc public class func fetchRequest() -> NSFetchRequest<HistoryList> {
        return NSFetchRequest<HistoryList>(entityName: "HistoryList")
    }

    @NSManaged public var date: Date?
    @NSManaged public var time: Int16

}

extension HistoryList : Identifiable {

}

@objc(HistoryList)
public class HistoryList: NSManagedObject {

}

CoreData Manager:

class CoreDataManager {
    
    let persistentContainer: NSPersistentContainer
    
    init(){
        persistentContainer = NSPersistentContainer(name: "HistoryModel")
        persistentContainer.loadPersistentStores { (description , error) in
            if let error = error {
                fatalError("Core Data Store faild \(error.localizedDescription)")
            }
        }
    }
    
    func saveHistory(time: Int16, date: Date) {
        let history = HistoryList(context: persistentContainer.viewContext)
        history.time = time
        history.date = date
        
        do {
            try persistentContainer.viewContext.save()
        } catch {
            print("failed to save \(error)")
        }
    }
    
    func getAllHistory() -> [HistoryList] {
        
        let fetchRequest: NSFetchRequest<HistoryList> = HistoryList.fetchRequest()
        
        do {
            return try persistentContainer.viewContext.fetch(fetchRequest)
        } catch {
            return []
        }
    }
    
    func deleteHistory(history: HistoryList) {
        persistentContainer.viewContext.delete(history)
        
        do {
            try persistentContainer.viewContext.save()
        } catch {
            persistentContainer.viewContext.rollback()
            print("Failed to save context \(error)")
        }
    }
}

i cannot find the problem

make coredata and i get error, I went through all the messages here and I tried everything and it doesn't work!

DrikiDev
  • 21
  • 2

0 Answers0