views:

275

answers:

4

hello, i have a very complicated problem that i would like to share with you and maybe someone can answer it for me. before i start i have to say that i am very new in this.

So, i have a coredata iphone app (much like the recipes app) that uses a pre-populated sql database. The user can add/edit his own data but the default data cannot be deleted. the useres data are ALL saved in the same sql database.

QUESTION: what do i have to do in order to: - update some (not all) of the default data that are stored in the sql database without "touching" the user's data? (the model will stay the same - no new entities etc-) (if the user uninstall the app and then reinstall the new version everything will be ok but i dont want to do this, obviously).

can someone PLEASE help in coding level?

A: 

Since you have entered the default data, you must be knowing the Ids/keys for those records. All you need is an update script that would change the default data.

danish
i have managed to update without a problem my default data by replacing the old sql with the new updated one. however i loose all the user entered data.i would appreciate a more detailed (if possible) answer/ tutorial to guide me towards a solution. thank you again for your time!
treasure
A: 

Core data explicitly supports model versioning and provides facilities to migrate your data between versions. This should contain the information you need. Link to Developer Docs for Migration

Kevin
thanks for the quick reply. however my problem is slightly different and i would appreciate some tutorial link or some code to start with.i have seen the link you are giving bus i have to say i a bit thick and dont quiet get it.thank you in advance for all the information you can give me...
treasure
A: 

To support adding new entities etc. later on, you want to use versioning and automatic light-weight migration which is described here:

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweight.html#//apple_ref/doc/uid/TP40008426-SW1

Basically you create a new version of your data model using the Design->Data Model menu item in Xcode, then make a few code changes. This will cause Core Data to automatically migrate an older model to the newer one. You are limited in what kinds of changes you can make. You can add new entities, and either add optional attribute to existing entities, or required attributes with default values set.

One thing that caught me out is that the way you load the core data NSManagedObjectModel changes when you want to use versioning and migration. Without migration you probably have this:

NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:nil];

Once you start using versioning and migration this needs to change to something like this:

NSString *path = [[NSBundle bundleForClass:self.class] pathForResource:@"DataModelName"
                                                                ofType:@"momd"];
NSURL *url = [NSURL fileURLWithPath:path];
NSManagedObjectModel *model = [[[NSManagedObjectModel alloc] initWithContentsOfURL:url] autorelease];
Mike Weller
A: 

FIXED thanks!

None of the above was the right answer!

fixed it on me own.

however you have pointed to the right direction.

thanks for your help and support!

treasure
You should delete most of your answers that are not answers and then select one of these as the right answer. Otherwise you will not have a history of answering questions and it is less likely your next question will receive an answer.
Marcus S. Zarra
And if you are going to answer your own questions, you should **answer** your question. In other words: what was wrong? what did you do to fix it? Just say "i got it working kthxbai" is totally unhelpful for anyone who has the same (or similar) problems in the future and comes across this.
Dave DeLong