我有一个带有关键字的实体词是一个字符串类型的uniqueConstraint。现在,我必须从文本文件中导入大量(>100000条记录)带有新关键字的单词。我尝试创建coredata NSManagedObject并插入到NSPolicyObjectTrump上下文中,以便将新关键字与旧关键字合并。但不幸的是,由于coredata解决冲突的过程,我的上下文保存项目进展缓慢(2-3分钟)。那么,哪种方法是导入这么多项目并确保没有违反coredata上的uniqueConstraint的最佳方法?我是否应该预先创建sqlite,以及如何用相同的对象模型迁移sqlite文件?谢谢
发布于 2018-03-15 05:44:49
- Fetch all entities with that have the same ID of the element you are inserting (with ONE fetch request)
- Inserted the fetched elements into a dictionary where the key is the unique Id and the value is the mananagedObject that you fetched
- For each element see if you already have a duplicate. If you do then update or ignore it (depending on your application logic). If you don't have one then insert it
- Save the context before moving on to the next batchhttps://stackoverflow.com/questions/49276084
复制相似问题