coredata - 交付/设置默认数据 [英] coredata - deliver / setup default data

查看:123
本文介绍了coredata - 交付/设置默认数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用coreData在我的iOS应用。这是可能的,用户添加,删除数据存入数据库。
我必须提供默认的数据(一些不同的数据集)。
此刻,我创建首先应用程序启动数据库。我从一个CSV文件中读取的数据与它创建数据库。
CSV文件是在应用程序沙箱;在coreData(managedDocument)是ApplicationDocument(创作上运行...)。

I use coreData in my iOS App. It's possible, that the user Add, Delete Data into the Database. I have to deliver default data ( some different data-sets ). At the moment, I'm creating the database by first Application launch. I read data from a csv file an create the database with it. The csv is in the Application sandbox; the coreData (managedDocument) is in ApplicationDocument (creation on runtime...).

它的工作非常适合我 - 但我问我,将苹果公司允许,如果我推到应用在AppStore

It works perfect for me - but I ask me, will Apple allow that, if I push the App to the AppStore?

推荐答案

有什么错这一做法,并不能成为拒绝的理由。也有另一种方式来做到这一点。您可以创建数据库你现在做的方式,复制 .sqlite 文件,并提供为默认的数据库。然后将其复制上的应用程序第一次运行。下面code将做到这一点:

There is nothing wrong with this approach and it can't be a reason for rejection. There is also another way to do it. You can create the database the way you do it now, copy the .sqlite file and provide it as your default database. Then copy it on app first run. The following code will do it:

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent: @"YourDBName.sqlite"];
    if (![fileManager fileExistsAtPath:storeURL.path]) {
        NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"YourDBName" ofType:@"sqlite"];
        if (defaultStorePath) {
            [fileManager copyItemAtPath:defaultStorePath toPath:storeURL.path error:NULL];
        }
    }

通过这种方法,你将不再需要提供您的 CSV 文件在你的包。

With this approach you will not need to include your csv file in your bundle.

这篇关于coredata - 交付/设置默认数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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