views:

354

answers:

2

I noticed several questions related to this topic go unanswered. Is this such a gray area that nobody really understands it?

Here is my problem: I am a midway in the development of my app and the app has never been used ouside of my iphone simulator.One of the attributes in my core data structure requires a type change.Since my app has never been used outside of my iPhone Simulator, I first deleted the sqlite file. Doubling the effort of this step, I also went into iPhone Simulator menu and selected "Reset Content and Settings...".

Than, I edited the xcdatamodel file and changed the type of my attribute. I saved the file and exited. Without any other changes, I compiled. I expected it to fail because of my type change. It did not! After this, I assigned a value with new type to my attribute and it fails to compile?!

Is there something else that I need to do for the change to take an effect? I would really, really appreciate an answer to my question.

Thank you!

+1  A: 

Core Data sometimes acts weird until you do Build -> Clean to build from scratch.

Jaanus
I did that too. Forgot to mention it.
San
+1  A: 

When you change the model and there is no sqlite file then Core Data will just create one off of the current model, so your first instance makes perfect sense.

In your second instance, if you did not delete the sqlite file (or reset the sim) between those two iterations you would get an error because the sqlite file already exists from the last run and it no longer matches the model.

Whenever you change the model you need to either version it or delete the sqlite file. Otherwise they will not match and produce an error.

If that is not the issue then it would be very helpful if you gave the details of the error you are seeing.

update

I'd still like to know the right way of dealing with the changes in core data in early development stages when there should not be a need for the migration.

The right way is to delete the application / reset the simulator and start with a fresh sqlite file. There is no other option other than migration and as you surmised, that is incorrect during development.

Marcus S. Zarra
So, I finally am moving forward with this. What I ended up doing is delete the entry completely and than try to run it...Sort of like forcing whatever keeps the information about core data to recognize that something is changing.(I would love to say it is sqlite file, but I did delete this one as I mentioned it in my original post.).This is probably not the best approach, but it's gotten me through.I'd still like to know the right way of dealing with the changes in core data in early development stages when there should not be a need for the migration.
San