Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode Cant' Edit CoreData Model

Tags:

ios

core-data

After adding a CoreData Model to my existing project using

File > New > File... > Core Data > Data Model

I am unable to edit the model. The project now includes a .xcdatamodeld package reference, but clicking on it in Project Navigator has the same effect as clicking on a folder or group, the current editor does not change. Also right clicking the reference and selecting "Open As >" lists no potential editors. Furthermore, opening the file inspector panel only lists settings for "Identity" "Target Membership" and "Text Settings", it does not list settings for "Core Data Model" or "Versioned Core Data Model"

Not that this should have any effect on XCodes ability to recognize a file type, but I have also referenced CoreData.framework in build phases, and included the necessary Core Data properties in the AppDelegate.

What's strange is I have opened the .xcdatamodeld package in Finder to expose the internal .xcdatamodel (note no trailing 'd'). Double clicking that file will open XCode with the Core Data Model Editor as expected.

Even stranger still is, I created a new projected and clicked the "Use Core Data" check box. Doing so allowed me edit the data model by selecting the .xcdatamodeld reference in the Project Navigator. Hence my machine and XCode are capable and configured to edit CoreData files.

It's as if XCode is unable to use Core Data unless the original project was created with the "Use Core Data" check box.

Has anyone experienced this issue, were you able to fix it, and how?

Thanks!

like image 975
Adam Ritenauer Avatar asked Dec 05 '12 16:12

Adam Ritenauer


2 Answers

Turns out I was attempting to add the Data Model to a group which referenced a specific folder in which to store it's children. That folder however did not exist. This cause XCode to place the data model in the project root, but at the same time reference it as residing 2 directories above the project root. What's even odder is that XCode didn't list the file as missing by displaying it in red. Either way XCode ignored the file when clicked in Project Navigator, because it didn't really exist where it thought it did. Moral of the story is: check your file paths and configured group paths.

like image 83
Adam Ritenauer Avatar answered Oct 06 '22 00:10

Adam Ritenauer


I ran into this issue today, and the problem was that my .xcdatamodel file was packaged inside itself (strange, I know). Here's how I fixed it:

  1. I found my File.xcdatamodel file in Finder.
  2. Right-clicked and selected Show Package Contents.
  3. Inside was another copy of File.xcdatamodel. I copied that to my Desktop.
  4. I then dragged that file into Xcode and it opened.

What a relief. :) I hope this helps someone else.

like image 36
Clifton Labrum Avatar answered Oct 06 '22 00:10

Clifton Labrum