开发者

Optimize time access to sqlite using coredata

I'm trying to use a pre-generated sqlite file containing 10 000 objects in a table.

I've created and added objects, with iPhone simulator, in the sqlite using coredata.

I've copy and past the sqlite contained in iPhone Simulator ressource f开发者_高级运维older (containing 10 000 objects), into my ressource folder in my project directory.

What i do at first launch of my app, is copy this generated database into my app document directory on the iphone using :

NSBundle * mainBundle = [NSBundle mainBundle];
        NSString *oldPath = [mainBundle pathForResource:@"MyBase" ofType:@"sqlite"];
        NSString *newPath = [[app_delegate applicationDocumentsDirectory] stringByAppendingPathComponent: @"MyBase.sqlite"];
        BOOL copied = [[NSFileManager defaultManager] copyItemAtPath:oldPath toPath:newPath error:&error];
        if (!copied) {
            NSLog(@"Moving database from %@ to %@, error: %@", oldPath, newPath, error);
        }

It works fine, but i have the following problem : Comparing access to the original MyBase.sqlite (created on my device and filled with the same 10 000 objects) with the new copy, all access on tables take 3 times more time than on the normal generated MyBase.sqlite.

I wonder if when generating sqlite on simulator, indexed attribute does not exist? I need help!


Your using a fairly common technique and it does not normally cause any issues. Core Data cannot tell the difference between a store just created and an old one if both stores use the same data model.

The only explanation I can think of is that you are using two different system/API versions such that the store file is subtly different. If the version on device is older/newer than the version on simulator you might have problems.

That's just a wild guess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜