Home > front end >  Xcode CoreData Add Relationship - Editor switch missing in Xcode 14.0.1
Xcode CoreData Add Relationship - Editor switch missing in Xcode 14.0.1

Time:10-13

Is there a workaround method to add a relationship in Core Data without using the 'Graph Editor' to drag from one entity to another?

There is an open Feedback assistant report - FB11598200 that states there is a potential fix identified.. which is nice.. but I am stopped in my development waiting for the Graph Editor function to be added back so that a relationship can be added to the Core Data Model.

I have tried using the relationship section of the Core Data Entity Editor.. and it all looks okay.. but the actual relationship apparently has to be created first with Graph Editor to actually make it work, as stated in the documentation.

To add a relationship in core data between entities the ‘graph editor style’ is used to drag from from one entity to another. The ‘Editor Style’ switch is missing in Xcode 14.0. The switch was located in the bottom right corner of the data model tool.

The switch is described and shown on the Documentation article ‘Core Data > Modeling Data > Configuring Relationships’ in the section ‘Add Relationships’.

To demo, try the example WWDC22 app used in session 10119 ‘Optimize your use of Core Data and Cloud Kit’. Click on the data model in the Xcode left toolbar. The data tool opens. The switch is missing. A new relationship can not be added...

I tried the Xcode current beta (Xcode 14.0.3) and tried migrating back to the last Xcode 13.4.1 from my backups.. The restored app from backup does not start in macOS 12.6

Ideas for workarounds while waiting for Xcode 14.1 ???

CodePudding user response:

...the actual relationship apparently has to be created first with Graph Editor to actually make it work, as stated in the documentation.

This is not true. The documentation describes one way of doing it, but not the only way. The graph editor is sometimes nice but it has never been necessary. Some of us never use it.

In the table view (the only view currently available in Xcode 14) you use the "Relationships" section of the editor to create and configure relationships.

For example, my sample model has an Event entity and a Venue entity, and I want to add a to-one location relationship from event to entity, with an inverse relationship named events. First I select Event and click the " " button under "Relationships":

enter image description here

Then I set up the name and destination entity for the relationship. Inverse is blank for now because I haven't created the other side of the relationship yet:

enter image description here

Next I select the Venue entity and click " " under "Relationships" again, and set up the relationship like this. Now I can set up the inverse, which is the relationship I created above:

enter image description here

I also made sure to select "To Many" in the inspector on the right side of the window.

Now I'll go back to Event to check that it's correct. Since I set up the inverse relationship in the previous step, it's already correct here.

enter image description here

  • Related