1

尝试执行 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'

当在构造函数中正确指定时,错误日志显示“实体(空)”。

我正在运行这是一个测试环境,想知道 NSBatchUpdateRequest 是否支持带有 NSInMemoryStoreType 的 NSPersistentStoreCoordinator。我在文档中找不到任何内容说它不受支持。

下面是我正在使用的代码。实体和属性参数是正确的,不应引起问题。

-(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;
}

如果有人有任何想法,我很想听听。

4

1 回答 1

2

指南

重要提示:批量更新仅在您使用 SQLite 持久存储时可用。

对不起。也许它会在 iOS 11 中工作。¯\_(ツ)_/¯

于 2017-04-07T04:22:25.607 回答