使用SQLite和CoreData进行批量插入

محم*_*نور 7 sqlite core-data insert bulk ios

我有一个使用SQLite作为持久性存储的CoreData模型.在对每条记录进行一些处理之后,我需要插入大量的行.有没有办法将这些命令发送到SQLite

PRAGMA synchronous=OFF
PRAGMA count_changes=OFF
PRAGMA journal_mode=MEMORY
PRAGMA temp_store=MEMORY
Run Code Online (Sandbox Code Playgroud)

我需要加快处理时间,因为它需要几个小时才能完成.

任何提示将不胜感激.

谢谢

Chr*_*nle 12

将商店添加到商店协调员时,可以指定编译指示:

NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];
[pragmaOptions setObject:@"OFF" forKey:@"synchronous"];
[pragmaOptions setObject:@"OFF" forKey:@"count_changes"];
[pragmaOptions setObject:@"MEMORY" forKey:@"journal_mode"];
[pragmaOptions setObject:@"MEMORY" forKey:@"temp_store"];
NSDictionary *storeOptions =
    [NSDictionary dictionaryWithObject:pragmaOptions forKey:NSSQLitePragmasOption];
NSPersistentStore *store;
NSError *error = nil;
store = [psc addPersistentStoreWithType:NSSQLiteStoreType
            configuration: nil
            URL:url
            options:storeOptions
            error:&error];
Run Code Online (Sandbox Code Playgroud)

(改编自持久存储功能)

我强烈建议您阅读"有效导入数据".

相关文档: NSSQLitePragmasOption 有效导入数据