iOS CoreData - 使用现有索引预填充db [英] iOS CoreData - prepopulate db with existing indexes

查看:127
本文介绍了iOS CoreData - 使用现有索引预填充db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个项目,我需要预先填充一个coredata数据库与现有的数据。

I am building a project where I need to prepopulate a coredata database with existing data.

我建立了一个解析器在iOS模拟器中创建sqlite文件,一切工作正常。
我使用单个实体,其中一个属性是索引。
将我的数据文件解析为核心数据后的性能非常好,一切都很好。

I built a parser to create the sqlite file in the iOS Simulator, everything works fine. I am using a single entity, and one of the attribute is indexed. Performance after parsing my data file into core data is great, everything is good.

现在我在项目中使用生成的sqlite文件相同的数据模型,相同的索引等...和第一次启动我复制db文件以预填充数据

Now I am using the generated sqlite file (~200Mb) in project with same data model, same index, etc... and on first startup I copy over the db file to prepopulate the data

    NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"myproject" ofType:@"sqlite"];
    NSString *storePath = [[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent: @"myproject.sqlite"];

    NSError *error;
    if (![[NSFileManager defaultManager] fileExistsAtPath:storePath]) 
    {
        if ([[NSFileManager defaultManager] copyItemAtPath:defaultStorePath toPath:storePath error:&error])
            NSLog(@"Copied starting data to %@", storePath);
        else 
            NSLog(@"Error copying default DB to %@ (%@)", storePath, error);
    }

复制工作正常,数据可以正常访问。
然而,性能是可怕的,并且索引显然没有被使用。

看看复制操作后sqlite文件的大小,它从200Mb到120Mb。

在模型中一切看起来一切正常,需要索引的内容将被检查为已建立索引。



1)有没有办法使索引数据不被删除复制sqlite结束?

2)是否可以通过编程方式重建索引?

3)任何其他想法?

The copying works fine, and the data can be accessed normally. However the performance is terrible, and the index is clearly not being used.
A look at the size of the sqlite file after the copy operation, it went from 200Mb to 120Mb.
Everything looks alright in the model, what needs to be indexed is checked as indexed.

1) Is there a way for the index data not to be removed when copying the sqlite over?
2) Is it possible to programmatically rebuild the index?
3) Any other thoughts?

推荐答案

看起来问题是,项目没有得到很好的测试之间清洁,它可能是一个错误在Xcode 4.3我当时使用。

Looks like the problem was that the project didn't get cleaned well in between tests, it could have been a bug in Xcode 4.3 I was using at the time.

同样的方法现在正常工作。

The same methodology is working fine now.

这篇关于iOS CoreData - 使用现有索引预填充db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆