2017-04-07 56 views
1

当我尝试执行NSBatchUpdateRequest时,我总是收到以下错误。NSBatchUpdateRequest抛出NSInternalInconsistencyException

*** 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' 

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

我正在运行这是一个测试环境,并想知道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; 
} 

如果有人有任何想法,我很乐意听到它。

回答

1

guide

重要:批量更新,当您使用一个SQLite持久性存储才可用。

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

相关问题