3

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.

  1. Should I make these changes through a lightweight migration? That is, should I be creating another xcdatamodel?

  2. 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

anayini
  • 227
  • 1
  • 3
  • 11

1 Answers1

5

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.

  1. In Xcode, click on your project file.
  2. Click the Build Settings tab.
  3. Search for MOMC.
  4. 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.

Community
  • 1
  • 1
BradzTech
  • 2,755
  • 1
  • 16
  • 21