Hi everyone!
I have a little question regarding the Batch updates example in chapter 4.
In the example the code updates all “Venues” to be my favorites like this:
let batchUpdate = NSBatchUpdateRequest(entityName: "Venue") batchUpdate.propertiesToUpdate = [#keyPath(Venue.favorite) : true] batchUpdate.affectedStores = coreDataStack.managedContext.persistentStoreCoordinator?.persistentStores batchUpdate.resultType = .updatedObjectsCountResultType batchUpdate.predicate = NSPredicate(format: "%K == %@", #keyPath(Venue.priceInfo.priceCategory), "$$$") do { let batchResult = try coreDataStack.managedContext.execute(batchUpdate) as! NSBatchUpdateResult print("Records updated \(batchResult.result!)") } catch let error as NSError { print("Could not update \(error), \(error.userInfo)") }
But what if I just want to update the ones with the price category = “$” ?
I this predicate to the NSBatchUpdateRequest :
batchUpdate.predicate = NSPredicate(format: “%K == %@”, #keyPath(Venue.priceInfo.priceCategory), “$$$”)
But the app crashes with this error:
Bubble Tea Finder[77429:6687874] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘keypaths (joins) not supported in batch update statements’
Is there a way to update this Venues without fetching them in memory first?
Thanks!