您使用了什么迁移策略?
在 XCode 中,您可以生成映射模型,并查看将发生的更改,包括索引。
我建议简单地添加映射模型,验证索引更改是否指定,然后进行自动轻量级迁移:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,nil];
NSPersistentStore *migratedStore = [persistentStoreCoordinator addPersistentStoreWithType:nil configuration:nil URL:storeURL options:options error:&error];
migrationWasSuccessful = (migratedStore != nil);
持久存储协调器将自动发现映射模型,并使用它来执行迁移。听起来运行时推断模型对将索引应用于实体属性并不敏感。