预加载核心数据数据库用黑色UIManagedDocument [英] Pre load core data database coming up black with UIManagedDocument

查看:183
本文介绍了预加载核心数据数据库用黑色UIManagedDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi支持专家...
我正在写我的第一个iPad应用程序,并有一个工作beta版本,解析一个XML文件创建一个 UIManagedDocument 核心应用程序启动时的数据库。然而这需要很长时间,我想做一次离线,并包括初始数据直接到我的应用程序包。



我首先按照命令行实用程序的方法,参见这里工作,直到我导入.sqlite文件和尝试编辑 persistentStoreCoordinator 方法 - 我使用 UIManagedDocument ,所以没有<$ c $在 AppDelegate - persistenStoreCoordinator Cocoa / Conceptual / CoreData / Articles / cdUsingMOM.htmlrel =nofollow>此页面在某些情况下,您不必编写任何代码来加载模型。如果您使用基于文档在Mac OS X上的应用程序, NSPersistentDocument 管理为您查找和加载应用程序的模型的任务。



然后尝试从模拟器中的我的应用程序的工作版本中复制 UIManagedDocument ,如 persistentStore 是空的,因此我的表也是。这正是这里提出的问题,但是给出的响应这个问题让我回到修改 NSPersistentStoreCoordinator 方法,我没有。



我添加了一个测试 NSFetchRequest 到我的代码中,我将 UIManagedDocument 从我的应用程序包复制到文档目录 - code> UIManagedDocument 在我的应用程序包中为空。我试着从查找器中拖放和处理使用终端 - persistentStore文件似乎被正确移动和大小106 KB,但我仍然在我的应用程序中获得一个空数据库。



有关如何使此工作有效的任何建议吗?



我需要使用 configurePersistenStoreCoordinatorForURL:ofType:modleConfiguration:StoreOptions:error:根据 UIManagedDocument 类参考 - 如果是这样,

我需要添加一些核心数据方法到我的AppDelegate,所以我可以修改我的 persistenStoreCoordinator 方法 - 如果是什么这个方法必须这样做吗?



我最好使用我的命令行创建的.sqlite DB或 persistentStore UIManagedDocument 似乎使用?

解决方案

商店协调员通过 parentContext

  document.managedObjectContext.parentContext.persistentStoreCoordinator 

或者,如果你只是意味着你没有访问构建永久存储的方法核心数据栈是构建的,那么它看起来像是为此目的的钩子(如你所提到的):


configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:自定义加载或创建持久存储。


但是在文档中对该方法的讨论不能解释什么做得很好。也许你可以覆盖它,看看什么对象是和已经在堆栈中创建,可能有一个初始化的协调器附加到父上下文,供您配置。在 NSPersistentDocument 上类似命名的方法的文档是这样的,所以也许 UIManagedDocument 也是。


Hi supportive experts... I'm writing my first iPad app and have a working beta copy that parses an XML file to create a UIManagedDocument Core Data DB on app start up. However this takes a long time and I would like to do it once off line and include the initial data directly into my app bundle. Needless to say I'm hitting a wall trying to get it to work.

I first followed the command line utility approach see here This worked until I imported the .sqlite file and tried to edit the persistentStoreCoordinator method - I'm using a UIManagedDocument and so don't have a persistenStoreCoordinator method in my AppDelegate - this page quote "In some cases, you do not have to write any code to load a model. If you use a document-based application on Mac OS X, NSPersistentDocument manages the task of finding and loading your application’s model for you."

I then tried to copy the UIManagedDocument from a working version of my app in the simulator as per this StackOverFlow question This seemed to work except that the persistentStore is empty and hence my table is also. This is exactly the problem asked here but the response given to that question takes me right back into modifying the NSPersistentStoreCoordinator method that I don't have.

I added a test NSFetchRequest into my code where I copied the UIManagedDocument from my app bundle into the documents directory - so I know that my UIManagedDocument in my app bundle is empty. I have tried dragging and dropping from finder and coping using terminal - the persistentStore file seems to be correctly moved and have size 106 KB but I still get an empty DB in my App.

Any suggestions on how to get this to work?

Do I need to use configurePersistenStoreCoordinatorForURL:ofType:modleConfiguration:StoreOptions:error: as per the UIManagedDocument Class Reference - if so how would I do it?

Do I need to add some of the core data methods into my AppDelegate so I can modify my persistenStoreCoordinator method - if so what else does this method have to do?

Am I better using the .sqlite DB that my command line utlity created or the persistentStore UIManagedDocument seems to use?

解决方案

You can access the persistent store coordinator through the parentContext:

document.managedObjectContext.parentContext.persistentStoreCoordinator

Or, if you just mean you don't have access to the method that builds the persistent store when the core data stack is built, then it looks like this is the hook that's intended for that purpose, (as you mention):

Override configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error: to customize the loading or creation of a persistent store.

But the the discussion for that method in the documentation doesn't explain what to do very well. Perhaps you could override it and see what objects are and aren't already created in the stack, there maybe an initialised coordinator attached to the parent context for you to configure. The documentation for the similarly named method on NSPersistentDocument is like this so perhaps UIManagedDocument is also.?

这篇关于预加载核心数据数据库用黑色UIManagedDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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