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

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

问题描述

我在我的 iOS 应用程序中使用 coreData.用户有可能在数据库中添加、删除数据.我必须提供默认数据(一些不同的数据集).目前,我正在通过首次应用程序启动创建数据库.我从 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,Apple 会允许吗?

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

推荐答案

这种方法没有任何问题,不能成为拒绝的理由.还有另一种方法可以做到.您可以按照现在的方式创建数据库,复制 .sqlite 文件并将其作为默认数据库提供.然后在应用程序第一次运行时复制它.下面的代码将做到这一点:

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天全站免登陆