someone please explain when should I increase the xcdatamodeld version? I google a lot, there are all about migration, but when should I increase the version?
Currently if I make change in my xcdatamodeld such as add entity or add attribute, I will recreate nsmanagedobject subclass. But I am not sure what situation that I have to increase the xcdatamodeld version.Please someone explain it. Thanks!
I think of it as a tool for helping users of my app migrate from the previous data model to the new data model. So I don't bump the version up unless I have to "release" it in some fashion (app store, or internal testers). Even then, if I have a small group of testers, I may just tell them to delete and reinstall so that I don't have to muck with it.
If a user with the old data model installs your app update with a new data model, they will crash unless you instruct the data model to "migrate".
Related
I'm actually developping an iOS Application and I'm facing a problem. In my application I have to store two kind of data : a product catalog, and a user preferences list on these products.
The catalog is a sqlite database and I need to update my catalog product at every build on xcode. No problem for this one I've added the file in the "Copy Bundle Resources" of the "Build Phases" of my project. So every time I build my application on xcode, the iPhone gets an updated database.
My problem is : I'd also like to store user preferences on these products that have to persist between xcode builds.
Question :
Is it possible to do something like this?
If yes : How? Is it possible to store this data in a sqlite database? What kind of file architecture am I supposed to implement to do something like this?
I've actually made a lot of research on this subject, but I can't find a solution...
Correct me if I'm doing it wrong, but I think this is possible.
Thank you :)
I've found a solution. The thing is, I think it is possible to realize something like I described before but I don't know how to do it. I'm still interested in the solution if someone have it.
The solution is to decentralize databases by using Firebase. By using Firebase database solution I can persist data through xcode builds.
Hi I struck at core data migration issue. I have developed a app which is new version of an existing app in Appstore. But i don't have source code of previous version and don't know exactly that whether core data was used in old version or not. So how to update my app (which has core data) to Appstore without any crashes. Any quick solution please?
Since you mention in a comment that you want to ignore the old data, you don't need to do any kind of migration. Model migration is about updating existing data to work with a newer data model. The only danger would be if the old app used Core Data and your new app attempts to use a persistent store file with the same file name. Then your app would attempt to load the old data, since it would find that file with the correct name.
The easiest way to test this is:
Install the existing app (from the app store)
Use this app until you're sure it's saving some data
Install the new version from Xcode. Since it's an upgrade, it will overwrite the app store copy.
By then you'll know exactly what happens when upgrading. If you get a Core Data related crash, change your Core Data setup to use a different filename. Then delete the app from your iOS device and repeat the test from above.
I'm working to get rid of a bunch of warnings in our codebase of the form:
Entity.relationship should have an inverse.
In general, although our code does not reach through these inverses, it sounds like it is a good idea to put them in anyway.
My question is about how I would do this.
Should I make these changes through a lightweight migration? That is, should I be creating another xcdatamodel?
For the given data model, what if we already have multiple versions/migrations. For example supposed we have the ReportsDataModel. And underneath that are ReportsDataModel1, ReportsDataModel2, and ReportsDataModel3. It seems like XCode 7 is giving me the same warnings on each data model. So if I fixed them in a lightweight migration to ReportsDataModel4, it seems like it wouldn't get rid of the previous warnings.
What is the recommended way to get around this issue?
-Arjun
First of all, you would be correct that you should implement the inverse relationships, as Xcode requires them. It's a good database practice, and you can virtually ignore the excess relationships if you're not using them.
Yes, you should be able to perform a lightweight migration, that is, create a new data model and let Xcode infer the changes. Here, Apple states that lightweight migration supports adding relationships.
Regarding your second question, true, creating another data model will not actually solve the warning in the older ones. You must leave the older models in Xcode so it can compute the lightweight migration process. If you erase a model and a user updates from an older version that uses that model, their data will be corrupted. (However, if you haven't published a version of the app with a particular data model, you can delete that data model.)
However, you can try suppressing the inverse relationship warning entirely.
In Xcode, click on your project file.
Click the Build Settings tab.
Search for MOMC.
Set Suppress momc warnings on missing inverse relationships to Yes.
EDIT about getting rid of the warnings on only the old models: This question suggests that you could move the old data model out of Xcode and place it elsewhere, and add a Copy Files action to Build Phases to copy the file back in at compile time. This way the file and it's extraneous warnings could be out of your way. Sorry there isn't a less "hacky" solution.
I recently sended out an update of my app. Now I got some complaints from people who says that the app is always crashing. When I check it on the simulator and on device everything works properly.
Now my question is, has this something to do with my update.
Maybe this has something to do with my core database that I'm using or maybe something else?
Hope that anybody can tell me what the problem is?
Impossible to answer.
Log in to iTunes Connect and download the Crash Reports. You might be able to find the answer there.
Assuming you manage your code properly then you should have a version handy which is exacly that what you sent to the store last time. Install that on your device. Run it. Then upgrade your own device and debug it.
Have you performed an upgrade on your own devices?
Without knowing more from your crash reports this could be a CoreData migration issue (or lack of migration). If you changed your data model between versions you should have made sure a migration is performed (either automatically, or using a migration mapping).
If you did not do this the app will crash because of an managed object model vs. underlying database incompatibility error.
Read the Core Data Model Versioning and Data Migration Guide for more information on this.
I created one project with core data that will work with unchangeable database. And I don't want to write code in this project , that will programmatically populate this database. So, I create second project with core data, add existing xcdatamodel from first project without copying(only references). There i populate my database, open it with mozilla plug-in and it successfully filled. Then I copy ,my *.sqlite file and manually replace it with old file in first project. It causes error:"The model used to open the store is incompatible with the one used to create the store". But I use for both files the same xcdatamodelid. Where my error?
Sorry for my english, I really need help.
P.S. when I open sqlite file from first project and second (with commented code of populate base) in FileMerge - second is already empty. I appreciate any advice or help.
Karoly S nicely answers the question. I have a hint that I frequently employ that may prevent this out of sync situation. Instead of two Xcode projects trying to share one model file, just create one Xcode project with two targets. Each target will use the same model file, any class definitions derived from that model, and possibly other code. My second target is a Mac OS command line program that generates the database, while my first target continues to be the iOS app that reads that database. The Mac OS target will overwrite the database file in a project subdirectory, ensuring it's up-to-date. If I make any changes to the model, Xcode knows to update both targets.
Did you change your Model Definitions in any way? The error you are seeing is because there is some difference between the model from when you created it, and again from when you are trying to reference it. Are you running on the simulator? Try to delete both of your apps to clear the data related to it, as it might be out of date. Afterwards simply rebuild both of your projects as that will update your core data database.
EDIT: To clarify a bit more, your core data model is out of sync, this is generally caused by you building and running an app, and a database being created, then redefining your object model, this can be done in a variety of ways, most likely caused by the addition of an attribute or entity. So when you are trying to load the database there are fields that the app and core data are looking for, but are not there because they did not exist when the database was created. I hope this helps.