开发者

How to rebuild the diagram for a CoreData model

开发者 https://www.devze.com 2023-01-09 01:38 出处:网络
Xcode can be buggy when dealing with core data models and it has corrupted the diagram representing my model. The model itself still seems fine, but does anyone know开发者_JS百科 a way of getting Xcod

Xcode can be buggy when dealing with core data models and it has corrupted the diagram representing my model. The model itself still seems fine, but does anyone know开发者_JS百科 a way of getting Xcode to re-generate the diagram layout?


I ran into a similar situation where my .xcdatamodel file displayed elements that didn't exist and arrows emerging from nowhere.

I resolved it by moving the layout file entirely from the .xcdatamodel package and then reopening the project in Xcode (v3.2.3). The diagram layout was lost (no big deal), but only the appropriate entities appear in the graph. Once I saved the .xcdatamodel file, the new layout was replaced in the package.


I found a similar corruption of the graph layout still occurring in XCode 4.3.2.

I removed an entity and then graph layout appeared to show arrows from seeming random places.

I simply closed and re-opened all the Attributes and Relationships of each entity and the graph lines seemed to update.


I don't know of any way to rebuild the files.

The diagrams don't exist as separate files but are generated from the model files themselves on the fly. If the diagram is garbled then it is likely that the model file itself is corrupted. If it appears to work in code it might just be a previous version of the compiled mom file still in the built product.

You can poke around in the data model files. The xcdatamodel "files" are really bundles. If you remove the xcdatamodel extension from the name, they revert to ordinary folders. If versioned, you will find another xcdatamodel inside. Rename that one as well. Inside that folder, you will find two files called elements and layout. Rename them to elements.plist and layout.plist and you can open them as human readable plist files. However, I doubt they will provide much info but sometimes you can find and fix the corruption if it is obvious e.g. malformed xml.


I ran into a similar issue in which Xcode decide to put half of my entities way way down in the corner. We're talking tiny scrollbars far. I thought maybe if I tried printing it it would re-layout the file, but I had to cancel the print preview after it was 1% done after processing 8,000 pages.

The solution I found was to delete the layout file inside the model. To do this, I just right clicked on the Model.xcdatamodeld package and clicked "Show Package Contents", that gave me a Model.xcdatamodel file which I did the same things to, clicking "Show Package Contents". Then I dragged the layout file to my desktop (just in case) and reopened Xcode. This gave me all of my entities right on top of one another, allowing me to drag them out into a readable arrangement.


For Xcode 7+ with the single XML files, I found that closing and opening the "Attributes" section of the graph element caused Xcode to update and redraw that part of the graph.

I kept doing that for each element with problems until the graph was back to normal.

0

精彩评论

暂无评论...
验证码 换一张
取 消