简体   繁体   English

需要在应用程序中包含一个预先填充的与coredata兼容的sqlite db:这是我的策略如何实现?

[英]need to include a prepopulated coredata compatible sqlite db with app: here is my strategy How to implement?

So after doing a LOT of research on the web. 因此,在网上进行了大量研究之后。 I figured the best way to ship my app is to ship it with a sqlite db that is generated by coredata application. 我认为最好的发布应用程序的方法是将它与由coredata应用程序生成的sqlite db一起发布。

Now to go about it I have decide that the following needs to be done: 1) Convert the data into a CSV format 2) Create a Coredata Mac application on my desktop 3) Parse the csv file and feed the contents to the coredata application on my mac and save as sqlite db. 现在,我决定需要做以下事情:1)将数据转换为CSV格式2)在桌面上创建Coredata Mac应用程序3)解析csv文件并将其内容馈送到我的Mac,另存为sqlite db。 4) Since the coredata model on the mac and iPhone is the same the underlying sqlite db will be compatible. 4)由于Mac和iPhone上的coredata模型相同,因此底层sqlite db将兼容。 5) Include the sqlite db that was generated by my mac app with the iphone app. 5)将我的Mac应用程序生成的sqlite db包含在iphone应用程序中。

So the question then is: 因此,问题是:

To create a mac app where do I start? 要创建一个从哪里开始的Mac应用程序? So far these are the steps I can think of: 1) Create a Mac app in XCode with Core data 2) create the "schema" on the coredata model that maps to the CSV file data --??? 到目前为止,这些是我可以想到的步骤:1)在XCode中使用Core数据创建Mac应用程序2)在coredata模型上创建“模式”,以映射到CSV文件数据-??? This is where i get stuck!! 这就是我卡住的地方! What next ?? 接下来是什么 ?? Can someone help me please? 有人能帮助我吗? I cannot find any resources on the web for this or Im searching with the wrong keywords 我在网络上找不到与此相关的任何资源,或者我使用错误的关键字进行搜索

Thanks a lot! 非常感谢!

I have done a similar thing. 我做了类似的事情。 I generated the CoreData db in the app with an #ifdef section that generated the db. 我在应用程序中使用生成数据库的#ifdef部分生成了CoreData数据库。 That seemed simpler than creating a separate Mac application. 这似乎比创建单独的Mac应用程序简单。

If you need to change the CoreData db in the app just copy it to the Library or Documents directory on initial startup. 如果您需要在应用程序中更改CoreData数据库,只需在初次启动时将其复制到Library或Documents目录即可。 The only gotcha was that I had to change the db extension in the app so that Xcode would not make changes during compile/archive. 唯一的问题是我必须在应用程序中更改db扩展名,以便Xcode在编译/归档期间不会进行更改。

I did the exact same thing you wanted except I created a second target in my iPhone app that parses the csv and writes it out to core data. 除了在iPhone应用程序中创建了第二个目标以解析csv并将其写到核心数据外,我做了与您想要的完全相同的操作。 Run it in the simulator, you can find the sqlite file in /"home"/Libary/Application Support/iPhone Simulator/5.0/Applications/"the app"/Documents 在模拟器中运行它,您可以在/“ home” / Libary / Application Support / iPhone Simulator / 5.0 / Applications /“ the app” / Documents中找到sqlite文件

This way everything is kept in one project. 这样,所有内容都保存在一个项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM