Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.xcdatamodeld file not showing data model structure in Xcode

I have .xcdatamodeld file in my project but it not opening up into the data model.

When I click on the file in the left sidebar in Xcode, it continues to display the contents of the previously selected file instead of displaying the data model. Likewise, when I right click on the file and choose "Open As >", I cannot select to display it as a Data Model—nothing comes up. I checked out the code from the SVN repo and even the filer owner is not able to see it in his workspace.

like image 298
Abhinav Avatar asked Mar 12 '13 19:03

Abhinav


People also ask

How to add Data Model in Xcode?

Add a Core Data Model to an Existing ProjectChoose File > New > File and select the iOS platform tab. Scroll down to the Core Data section, select Data Model, and click Next. Name your model file, select its group and targets, and click Create. Xcode adds an .

What is use Core Data Xcode?

Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.


2 Answers

For some dark reasons, sometimes Xcode needs the xcdatamodeld fiel to be in the root folder. I wrote an answer here that explain how to do this, but also a workaround to have this file where ever you would like to.

Cheers!

like image 133
Kevin Delord Avatar answered Nov 01 '22 04:11

Kevin Delord


This is a symptom that I have seen from time to time. In at least one case, this was due Xcode having the wrong path stored in the path component of the XCVersionGroup section of the project.pbxproj file, and having an apparently unnecessary additional name component in that section. It would probably be possible to manually edit this file, but I'm always reluctant to monkey around with the project file directly, and fortunately there's an easier way.

  1. Navigate to your .xcdatamodeld file in the Finder. The easiest way to do this is Right click/Ctrl-click on the .xcdatamodeld file and select "Show in Finder".
  2. Drag the file from the Finder and drop it immediately above or below the current reference to the .xcdatamodeld in the Project Navigator in your Xcode project.
  3. Click OK to accept the import, ensuring that you are adding it to the correct targets. (Which targets are correct will depend on your project.)
  4. You will now have two references to the same file in your Project Navigator. Clicking on either of them will now bring up the desired data model structure.
  5. Remove the duplicate reference to the model file. Click on one of the file references (doesn't appear to matter which, though it may be better to remove the old one) and press Delete.
  6. In the resulting confirmation dialog, be sure to select "Remove Reference" only, and do NOT move the file to the trash. (The two references point to only one actual file in the file system. Moving to trash would thus trash the only copy.)

You're now left with just one reference to the data model, and it works.

One thing that appears to trigger this bug is moving the .xcdatamodeld file in the file structure on disk. Even after correctly re-associating the file with the new location (i.e., it no longer appears in red in the sidebar), the one section of the Project file mentioned above is not correctly updated, and thus the file is not treated fully correctly as an Xcode Data Model file.

like image 31
Duncan Babbage Avatar answered Nov 01 '22 04:11

Duncan Babbage