复制一个sqlite文件到storePath:没有什么(核心数据) [英] copy a sqlite file into the storePath : nothing in there (core data)

查看:86
本文介绍了复制一个sqlite文件到storePath:没有什么(核心数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个sqlite文件与Lita,我复制它(拖动它)到其他来源文件夹中的xcode(我检查了广场复制文件)。然后我试图检查文件是否被复制,但在这个文件夹:有没有复制到文档? :

i created a sqlite file with "Lita", i copied it (dragging it) into xcode in the "Other Sources" folder (and i checked the square to copy the file). I then tried to check wether the file is copied or not, but in this folder : there is nothing copied into Documents? :

my path : /Users/MyProfile/Library/Application Support/iPhone Simulator/4.3/Applications/154BC5C5-FF55-48B5-A7A0-A80496212ACB/Documents

和我的代码应该复制它,或者有一些我误解?

and my code that should copy it, or maybe there's something i misunderstood?

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator_ != nil) {
        return persistentStoreCoordinator_;
    }

    NSLog(@"my path : %@",self.applicationDocumentsDirectory);
    NSString *storePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"myCD.sqlite"];
    /*
     Set up the store.
     For the sake of illustration, provide a pre-populated default store.
     */
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // If the expected store doesn't exist, copy the default store.
    if (![fileManager fileExistsAtPath:storePath]) {
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"myCD" ofType:@"sqlite"];
        if (defaultStorePath) {
            NSLog(@"in if defaultStorePath");
            [fileManager copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
        }
    }

所以sqlite文件应该复制到iphone模拟器/4.3/etc。但是没有什么...

So the sqlite file should be copied into the iphone simulator/4.3/etc. but nothing is in there...

感谢

推荐答案

正确复制文件。

但是,如果它不是Core Data生成的存储文件,Core Data不能将其用作存储。

However, if it is not a Core Data generated store file, Core Data cannot use it as a store.

核心数据不是一个简单的SQLite包装,而是使用SQLite存储只是Core Data存储选项之一。核心数据必须以特定方式构建存储,并且核心数据sqlite模式未记录。你不能只删除任何SQLite文件,并将其用作Core Data存储。

Core Data is not a simple SQLite wrapper but instead using a SQLite store is but one of the Core Data store options. Core Data has to structure the store in a specific way and the Core Data sqlite schema is undocumented. You can't just drop any SQLite file in and use it as a Core Data store.

您需要将数据导入Core Data,并让Core Data创建存储并向其写入数据。然后,您可以将该文件包含在应用程序包中。

You will need to import the data into Core Data and have Core Data create the store and write data to it. Then you can include that file in the app bundle.

这篇关于复制一个sqlite文件到storePath:没有什么(核心数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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