现有项目问题的核心数据

发布于 2024-11-23 14:51:06 字数 786 浏览 1 评论 0原文

我正在使用 sqlite 作为持久存储协调器、核心数据模型、实体来迁移核心数据,我创建了所有内容,但现在我的问题是我不知道如何使核心数据将初始数据文件写入我放入的文件中主包。并且总是存在这样的错误:

-[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?
2011-07-14 17:37:59.409 SalePersonApp[1202:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'

当我将上下文分配给 appDelegate Context 时:

SalePersonAppAppDelegate *app = [[UIApplication sharedApplication] delegate];
        NSManagedObjectContext *context = app.managedObjectContext;

错误位于第二行。

现在我的 sqlite 文件是空的,因为正如我所说,我不知道如何使核心数据将我的实体写回 sql 文件。

谁能告诉我该怎么做。预先非常感谢。

I am migrating a core data using sqlite as the persistentStoreCoordinator, the Core Data Model, entities, I created everything, but now my problem is I don't know how to make Core Data to write initial data file to the file I put in the mainBunddle. And there is always error like this:

-[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?
2011-07-14 17:37:59.409 SalePersonApp[1202:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'

when I assign my context to the appDelegate Context:

SalePersonAppAppDelegate *app = [[UIApplication sharedApplication] delegate];
        NSManagedObjectContext *context = app.managedObjectContext;

Error was at the second line.

Right now my sqlite files are empty because as I told, I don't know how to make the Core Data write back my Entities to the sql file.

Can anyone tell me how to do this. Thanks so much in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2024-11-30 14:51:06

如果将持久存储放入应用程序包中,则它是永久只读的,因为应用程序包中的所有内容都是只读的。

要创建可写存储,您需要在捆绑包外部的应用程序目录之一(通常在 DocumentsLibrary 中)创建存储。

如果您需要提供预先填充的持久存储,请在 Xcode 中运行时使用 Core Data 填充该存储。然后将持久存储文件本身添加到构建目标,以便将其写入应用程序包中。应用程序第一次运行时,将持久存储从应用程序包复制到其中一个可写目录。然后正常打开副本。

If you put your persistent store inside the application bundle, then it is permanently readonly because everything inside the app bundle is read only.

To make a writable store, you need to create the store in one of the app directories outside the bundle usually either in Documents or Library.

If you need to provide a pre-populated persistent store, use Core Data to populate the store when run within Xcode. Then add the persistent store file itself to the build target so that it will be written into the app bundle. The first time the app runs, copy the persistent store from the app bundle to one of the writable directories. Then open the copy as normal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文