.xcdatamodeld file not showing data model structure in Xcode - ios

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.

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.
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".
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.
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.)
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.
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.
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.

I encountered the same issue in Xcode 6.3
The only solution that worked for me was to move the .xcdatamodeld file out of my 'Resources' folder and into the project root folder in the Xcode project explorer (location on the filesystem doesn't matter)
I'm still not sure why, just moving the location of the file in the project structure causes it to not show up at all when clicked.. but apparently, at least in my setup, it doesn't like living in the Resources folder..

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!

The .xcdatamodeld file is a package. It contains .xcdatamodel packages, one for each version of the model. Inside every .xcdatamodel there is a contents file, which is an XML with entities description. To see what is inside your packages, right-click them in Finder and choose Show Package Contents option.
Perhaps you didn't add the contents file into your repository. This way you will not be able to see your model when you create a brand new working copy from it.

I was victim of this problem today on Xcode8.
I solved it simply by placing the xcdatamodeld file outside any group in the Project navigator (left pane). As soon as I move it into a group, I can't open the little guy anymore.

I had a similar problem with Xcode 7.3.1.
It turned out to be related to the way the data model packages were configured.
I discovered that there was one embedded model package nested inside another. Let's say a top level data model called FolderNodes.xcdatamodeld containing another with exactly the same name ... FolderNodes.xcdatamodeld. Inside FolderNodes.xcdatamodeld is the actual contents file that has the model info.
The solution for me was to drag the embedded package FolderNodes.xcdatamodeld ( number 2) into the Xcode project and NOT its enclosing folder.
Apple uses the package for versioning but I think the logic associated with moving the data model file somehow breaks the original package creating a redundant wrapper.

Make sure your Version Editor is not active.
Having the Version Editor open results in the xml code to be displayed instead of the Data Model. You will also not be able to choose Data Model in the context menu of the xcdatamodeld file within the Project Navigator.

Happens on XCode 8.3 as well.
For me, moving the physical file to a different folder, then deleting the original reference, then adding it back to same place and establishing the reference again does the job.

Related

Xcode 9 - Some folders marked with red text

In my project, there are some folders that have red text.
The project compiles and everything works, but I can't understand why only some folders have red text.
Check this.
It means they are not found on disk where your project believes they should be. Control-click and Show In Finder to see the folder location to locate the file and drag it back in to the project, and delete the bad reference.Missing. Maybe you moved them somewhere without deleting them from the project or something.
Edit: Don't delete it before add it first, and you should save backup from the files in another folder, also you have to use source controls like Bitbucket, GitHub, or GitLab.
The UI error feedback notifies you that the path is not found. You can select a new one using the folder icon in the right panel. In this way, all files in the folder keep the configuration so it is more convenient.
I illustrate it in the above screenshot.

Duplicate Xcode project uses old project_dir

I am trying to create a duplicate of my Xcode workspace. I have made a duplicate folder in Finder. Let's call the original Project_v1 and the duplicate Project_v2.
When I open Xcode in order to deal with all the additional issues i notice that my location/fullpath are both /Users/abcd/Desktop/Abcd/Project_v1/Project.xcodeproj (Relative to Group) even though I opened Project_v2 folder.
When I watch online tutorials about this the path is always the new path. If I choose Project_v2 by clicking the little folder icon under Identity and Type then my entire structure in left pane changes (folders go blue not yellow, project app icon turns to a folder etc).
How is it even possible that my project contained within Project_v2 is referencing v1? And how do I safely change it to v2 whilst keeping everything else correct?
Ok so basically I just have to keep ditching copies and starting again using a different name until somehow things kick in.
For some reason when I try to change the path of the project in the File Inspector it randomly either allows me to select the xcodeproj file or not. If it does I am ok. If it doesn't there's nothing I can do but start again.
The key is being able to change this path but seems random whether allowed to do so.
EDIT:
Seems the only way to be able to sort this out is to change the projects path to Absolute, choose the folder Project_v2 (not the xcodeproj file as this isn't possible), then change back to Relative to Group and then actually choose the xcodeproj file as the intended location.

How to change the name of an Xcode file folder?

(XCODE 5)
I may be wrong in calling it a file folder, but what I'm referring to is the folder that contains all the files that is created after making a new project. In my case, I saved my project onto the desktop, and originally named it something completely different. Now I want to change its name, but before when I changed the name of the folder it didn't work when I tried to build and run my app. The other question I had was how to move it to another location because same thing happened when I moved the project from the desktop.
I was also wondering what A or M or a ? mean beside the files on the left hand panel (inside the project)
In terms of renaming the folder, you're generally fine renaming the top level folder, but it can get messy when renaming one of its one of the subfolders. If you rename the subfolders, side affects include (a) messing up links in the Xcode project; and (b) if you're using version control, losing the connection between the previous change history and the new file. But if you're talking about the top level folder under which everything for the project is included, I've never had problems renaming that.
In terms of the A/M designation, a A means that new file has been added to the project; M means that an existing file has been modified. You'll only see these when your project is under version control (which is a checkbox you can check when creating your project.)

CoreData: Opening a standalone .xcdatamodeld file and changing current model version

I have a standalone .xcdatamodeld file which I want to edit as a standalone file, not inside a Xcode project.
I know I can edit specific .xcdatamodel files if I right click in the .xcdatamodeld directory and click "Show Package Contents". I can even create new .xcdatamodel files from the top menu (Editor > Add Model Version...).
However, I cannot change the current model version of the .xcdatamodeld file. This option does not show in the file inspection on the right panel.
As far as I know the name of the current version is stored in a plist file named .xccurrentversion inside the .xcdatamodeld directory.
Anyone knows how could I change this from inside Xcode?
I have had this happen before.
To fix it I just opened the file in vim (or textedit/subethaedit/your text editor of choice) and fixed the model version myself.
Make sure you do a search through the document for any references to the model version. I also believe that it may be mentioned in the .plist files that define your project/workspace, so you probably want to do a search in those files as well.

Unable to add datamodel in xcode4

I'm porting my iphone app to ipad, and therefore created a completely new project. After programming a while, i wanted to import the coredata model from my iphone project, so i can have the same coredata storage layout. but for some reason, xcode 4.2 wont let me use the imported model. after drag-and-dropping the versioned model (foobar.xcdatamodeld) into my ipad project (copying it to the destination), i am unable to select the current version, and the model will not show the arrow-indicator as well as no sub-models in the file-list on the left side of xcode.
even if i create a new datamodel (file -> new...), i get the same behaviour. i can't edit the model, because appearently it is not opened (clicking on the model in the file list will not change the editor window in the middle), i cannot add a version to the model (the menu item unter "editor" is not present), and i can't select any current version.
i noticed that the object inspector will state a path that is "Relative to group", with the path beeing "../foobar.xcdatamodeld" (which is "foobar.xcdatamodeld" in my iphone project), and the full path is beeing blank.
i even edited the model and xcode project files through vi, to make it look like the iphone ones, with no success.
so, right now i can't neither add a new datamodel, nor import the existing model.
can anyone help?
i have no idea if it's related, but i ran into a weird thing earlier today when copying resources from one project to another. i did the same thing (made sure i selected copy files into destination's group folder etc) and it didn't actually copy them - it was referring to the files in the project i was copying from. weirder still, the project couldn't actually "see" them (the file names were red).
i ended up getting around it by manually copying them into the "to" project's directory, and adding them from there.

Resources