开发者

iPhone: Should I move data from the application bundle to the documents directory?

I have noticed that in the CoreDataBooks example a default database is copied to the documents directory if the file doesn't already exist there:

if (![fileManager fileExistsAtPath:storePath]) {
    NSString *defaultStorePath = [[NSBu开发者_Go百科ndle mainBundle] pathForResource:@"CoreDataBooks" ofType:@"sqlite"];
    if (defaultStorePath) {
        [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
    }
}

My question is, does this double the space it takes up?

i.e. There are now 2 databases, one in the bundle one in the documents folder.

I have a much larger database and a whole bunch of images totaling to about 50mb. Is there another way to go about this without copying the data?


In the example this is done so there is a default file to write to. If this is not done, one would have to create the file in code. The reason for this is because the app bundle is in a sandbox where it is forbidden to write to.

If you need the database to be editable, you must move it outside the app bundle.


AFAIK, Apple strongly recommends against modifying files in the bundle. So if the data are read-only (like, most likely, your images), it's OK to keep it in the bundle. A mutable database is a whole another matter.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜