开发者

Connecting CoreData to my App on an iPhone Device

I apologize ahead of time for what I'm sure is a complete newbie lapse. Running my iPhone app on iPhone simulator - no problem. But开发者_运维问答 I loaded the app on an iPhone device for the first time and it appears as if the SQLite database I'm using (NSManagedObjectContext) isn't connected or didn't upload. The app installs but with no data. How do I get it all to upload and work on the device? I appreciate any help. lq


The first rule with Core Data is that you should never ever touch the store directly. It should be considered a black box and only accessed via the the Core Data APIs. Accessing the database directly is unsupported and can lead to data corruption.

What you should do instead is create a trivial desktop application (or command line is you are just importing from another source) and enter the data there. Once the data is entered then copy the sqlite file to your mobile application and include it in the bundle. That way you are accessing the file from Core Data. Since Apple can and does change the structure of that file without notice your application will be future proof.

update

If you have created a database using Core Data you can then take that sqlite file and add it to your Xcode project for your iPhone application. Xcode will then copy it into the app bundle when it compiles the project.


Looking a little deeper I found a link that answers my own question. So anyone with the same question, this solved the issue for me:

http://ablogontech.wordpress.com/2009/07/13/using-a-pre-populated-sqlite-database-with-core-data-on-iphone-os-3-0/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜