Question

I'm developing iOS application uses coredata.

I know how to change model current Version of xcdatamodeld in "XCode". But can i change it in program?

if can do it, please teach me.

Was it helpful?

Solution

No you cannot change the current version. But you also do not need to.

  1. You can create a model programmatically as suggested by @Adam.
  2. You can choose which model you wish to use with the -initWithContentsOfURL: method on NSManagedObjectModel.

Loading the current version is just a migration convenience and is not required.

Update

Thank you for answer. And i have a qustion. if i want to chose the current version by some cases, copy original xcdatamodeld file and put two xcdatamodeld files in project, original xcdatamodeld is set current version and copied xcdatamodeld is set another version, And i chose these files by initWithContentsOfURL method. Is this way possible?

That is possible but unnecessary. When you point the -initWithContentsOfURL to your momd it will choose the most recent version of the model automatically. If you point it at a mom file it will load a single model. Since the mom files are inside of the momd directory, you can keep just one versioned model and then load whatever version of that model you want. I do this quite frequently when I am doing all of the migration manually.

A mom is a xcdatamodel file compiled. A momd is a directory of compiled models and is the result of compiling a xcdatamodeld bundle (aka folder).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top