How can I make permanent the custom data I have manually put into my core data database? - iphone

Ok, I am admittedly pretty new to core data, and am still not quite as knowledgeable as I would like to be. I am doing some pretty basic data retrieval from the database using values that I went in and added myself (using the sqlite editor Base).
I got everything working in my simulator, and I thought that life was just dandy but I went in and installed the app on my 2g iPod touch, and when my pickerview went to go get data...there wasn't anything there! I guess it's not terribly surprising, but I was thinking that the app build would just copy the db that I had setup??
What is going on? What do I need to do to make it so that the pre-loaded data is available for any and all downloaders of my app?
Thanks!

The core data persistent store won't get automatically added to your app. You will need to add this file to your project so that it becomes part of the app bundle when you build the app. You can see what will happen in xcode after you've added this file under your target settings.
Additionally apple discourages modification of the SQLite data store directly outside of core data. You may be better off just using SQLite in that case. If you feel you really need core data, you may want to make a default SQLite database that is part of your app. The first time the app is run (or the data is reset) you can then import that data into your user's custom core data persistent store. See this portion of apple's documentation on how to import an existing SQLite database into core data. This allows you to have default data but gives you the flexibility of being able to reset the database easily.

Related

Updating an SQLite database on the iPhone

I have very little knowledge about app development, but I am updating an existing SQLite database (simple text changes to the html that is stored within the database). Everything works fine, but when I submitted the app to Apple the changes weren't showing when people upgrade (if you download it for the first time - straight from the App Store - it is fine, so the database must be saved to the cache).
Does anyone know how I can overwrite the existing database? People have said to change the file name of the database, but will this make the app run slower (will two databases be stalled in the cache). Also peoples data are stalled on the database (bookmarks etc.) so somehow that info still needs to be retained if possible.
Any help would be appreciated.
i also would recommend you to rename the database. thats the easiest and fastest way. rename your model and set it to the standard.
i am using this solution, too. my app is not running slower then before. just test it.
please also see this two links for adding new models to your project:
create new model version(apple)
How to Add Core Data to an existing Utility Application
I think that change should happened only in the build u r tested and not in you have uploaded on appstore.
So better way u upload it again... With all testing done.

Pre-existing Core-Data data

I've looked around for this but haven't found what I'm looking for. I need some data to basically come pre-loaded in the app. I know that I could just put it all in on the first launch but would like to stay away from a long load time on the first launch and have it already loaded.
Is it possible to insert entities into core-data so that they are hard-coded in?
Yeah, you include a a pre-filled data store in your app bundle and copy it from the bundle to the documents directory as part of the app launch process - check if the data store exists and, if not, do the copy. You do this prior to accessing the Core Data stack for the first time.
There are a few ways you could do this. The lazy programmer way is to enter your default data into the app, either on the phone or in the simulator, grab the data store file, and include it in your Xcode project. The downside is it doesn't work well if you need to go back and edit the data model later.
The other option is to create an editor app on the Mac that uses the same Core Data model as your iPhone app (they're compatible) and edit the data in your Mac app. Jeff Lamarche talks a bit about this in one of his blog postings. I've done something similar, except I wrote a command line tool to download the latest data from a web site (in my case, XML data) and parse the XML into NSManagedObjects.
This StackOverflow post talks about a bit more complex option of having two data stores - one for your system data and one for your user data - and letting Core Data use both stores at runtime.

How to add database layer in core data application

I am fairly new to core data technology and i searched a lot on how to add the database to a core data application.so can anybody guide me on how to integrate the database layer? i have seen the iphone tutorial on core data (i.e books example) but i am not able to understand how to .sqlite file has been included in that application
The SQLLite file is automatically generated at startup by core data, by the persistent store manager.
If you have a project generated to start with Core Data, look in the App Delegate at the persistentStoreCoordinator method - that's where it manages the file created and sets the path where it will exist. If there's an existing one it will make use of it, though you'd have to copy over a pre-loaded one into the writable path it sets up for the database.
Core Data is NOT a database, it is a persistent object store. You have no control over how the data is stored in the file. (So trying to get it to use your own designed database is a bad idea.) You only get to chose wether it uses XML, binary or sqlite as its backstore.
To see how your app gets the data from the file, look in the app delegate. (That is where most sample code put it.) You'll find some methods for the managed object context, and the persistent store coordinator. The latter will create the file if needed. Besides the save call during quit, or other relevant times, you don't have to do much with it. (You can do some stuff, but I can't recommend that when you're new to Core Data.)

Are there good iPhone SQLite3 tutorials which really start from scratch?

I always find something that starts somewhere in the middle, where the database already exists or where some special classes or files have already been added to the project. I want to see the first steps, since they're crucial. i.e. somebody said the database has to be copied into a readwriteable dir on the iphone. Anyone knows a complete tutorial on this?
(no, I don't want to use Core Data or OS 3.0)
You might consult these other similar questions:
"iPhone create SQLite database at runtime?"
"Where’s the best sqlite3 tutorial for iPhone-SDK?"
"Add SQLite Database to iphone app"
Additionally, the SQLiteBooks sample code that Apple provides takes you step-by-step through the process of copying an existing database from the resources directory of your application bundle to the application's Documents directory. It is a little more complex when working with the database, however.
Mobile Orchard also has a list of resources for SQLite on the iPhone.
The source code to my iPhone application Molecules is available, and for now it uses SQLite as a data store (that will be changing to Core Data soon). You may be able to pick something up from that.
What about SQLite Persistent Objects? I used it on my last project and it was cake.
http://iphonedevelopment.blogspot.com/2008/08/sqlite-persistent-objects.html
http://www.galloway.me.uk/2009/02/sqlite-persistent-objects/

Core Data Migration really Slow, Why does it happen at all?

I'm developing a desktop Mac OS X App that saves its very simple data into SQLite with Core Data and a companion mobile App for iPhone that simply needs to read data from the desktop App. Although they share the same Managed Object Model when I load the SQLite database on the mobile app the data takes several seconds to migrate the data. I really would like to avoid this long wait as it appears linearly related to the size of the SQLite file.
Why is data from the same Managed Object Model even needing to migrate at all?
Does anyone know of a way to avoid needing to migrate?
I've discovered what was causing this problem. Although it is probably very obvious I'll relate it so hopefully no one else will make this mistake...
I had two distinct Managed Object Models in my project. Having more than one seems to force Core Data to try migrating to figure out which data matches with which MOM.
As a solution I was able to manually merge the models so both data sources can be represented with the same MOM.