NSBatchInsertRequest

NSBatchInsertRequest appears to be missing from the Beta-2. Did anyone else get it to work?

Replies

It seems to be missing. This sample code is from 8:30 from the "Making Apps with Core Data" and throws an error when compiling "Use of unresolved identifier". Fingers crossed for inclusion in beta 3 😟


taskContext.perform {
            let insertRequest = NSBatchInsertRequest(entity: MediaCollection.entity(), objects: objectDicts)
            let insertResult = try? taskContext.execute(insertRequest) as! NSBAtchInsertRequest
            let success = insertResult as! Bool
        }

Hi


I try to use the "NSBatchInsertRequest". but the insertResult is nil, and my CoreData is empty

I use the viewContext of the "NSPersistentCloudKitContainer".



let container = NSPersistentCloudKitContainer(name: "CoreDataPerformance")
                    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
                        if let error = error as NSError? {
                            fatalError("Unresolved error \(error), \(error.userInfo)")
                        }
                    })
                   
                    try container.viewContext.setQueryGenerationFrom(.current)
                   
                    let moc = container.viewContext
                    moc.automaticallyMergesChangesFromParent = true
                    moc.perform {
                        let insertRequest = NSBatchInsertRequest(entity: Client.entity(), objects: clients)
                        let insertResult = try? moc.execute(insertRequest) as? NSBatchInsertRequest
                        if let success = insertResult as? Bool {
                            print("RESULT: \(success)")
                        }
                    }



This is the error I receive in the console.


2020-02-04 18:30:25.800705+0200 CoreDataPerformance[62836:778869] [error] warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'CoreDataPerformance.Client' so +entity is unable to disambiguate.

CoreData: warning: Multiple NSEntityDescriptions claim the NSManagedObject subclass 'CoreDataPerformance.Client' so +entity is unable to disambiguate.

2020-02-04 18:30:25.800846+0200 CoreDataPerformance[62836:778869] [error] warning: 'Client' (0x600000c50bb0) from NSManagedObjectModel (0x600001877480) claims 'CoreDataPerformance.Client'.

CoreData: warning: 'Client' (0x600000c50bb0) from NSManagedObjectModel (0x600001877480) claims 'CoreDataPerformance.Client'.

2020-02-04 18:30:25.800940+0200 CoreDataPerformance[62836:778869] [error] warning: 'Client' (0x600000c589a0) from NSManagedObjectModel (0x600001861680) claims 'CoreDataPerformance.Client'.

CoreData: warning: 'Client' (0x600000c589a0) from NSManagedObjectModel (0x600001861680) claims 'CoreDataPerformance.Client'.


Any ideas ?
Thanks

check my answer to this post: https://forums.developer.apple.com/thread/125374