1

I keep getting the following error when trying perform a NSBatchUpdateRequest.

*** Terminating app due to uncaught exception 

'NSInternalInconsistencyException', reason: 'Unknown command type 

<NSBatchUpdateRequest : entity = Person, properties = {
    "(<NSAttributeDescription: 0x6000000ff980>), name title, isOptional 1, isTransient 0, entity (null), renamingIdentifier title, validation predicates (\n), warnings (\n), versionHashModifier (null)\n userInfo {\n}, attributeType 700 , attributeValueClassName NSString, defaultValue (null)" = "\"sometitle\"";
}, subentities = 1'

The error log shows "entity (null)", when it is correctly specified in the constructor.

I am running this is a test environment and wonder if NSBatchUpdateRequest supports NSPersistentStoreCoordinator with NSInMemoryStoreType. I cant find anything in the docs say its not supported.

Below is the code I am using. The entity and property parameters are correct and shouldn't be causing the issue.

-(BOOL) updatePersonNamesFrom:(NSString*)oldName newName:(NSString*)newName {

    NSBatchUpdateRequest* updateRequest = [[NSBatchUpdateRequest alloc] initWithEntityName:@"Person"]; // The person model definitely exists

    NSLog(@"entity name: %@", updateRequest.entityName); // This logs the correct entity name

    // Adding or removing a predicate has no effect
    // [updateRequest setPredicate:[NSPredicate predicateWithFormat:@"name = %@", oldName];

    updateRequest.propertiesToUpdate = @{@"name" : newName}; // Name field definitely exists on Person

    NSError* error = nil;

    [m_context executeRequest:updateRequest error:&error];

    // Also tried this
    // [m_context.persistentStoreCoordinator executeRequest:updateRequest withContext:self error:&error];

    return error != nil;
}

If anybody has any ideas I would love to hear it.

user346443
  • 4,672
  • 15
  • 57
  • 80

1 Answers1

2

From the guide:

Important: Batch updates are only available when you are using a SQLite persistent store.

Sorry. Maybe it'll work in iOS 11. ¯\_(ツ)_/¯

Dave Weston
  • 6,527
  • 1
  • 29
  • 44