Question

I want to see what model each of my models are base on and possibly change it. I haven't been able to find anywhere to do this in Xcode. It seems that once you create a new model version, and select the model it's based on (using "Editor / Add Model Version..." and selecting a previous model with the "Based on model" drop down), there's no way to see your selection or change it.

The .xcdatamodeld and .xcdatamodel files are packages and you can examine them by right-clicking / "Show Package Contents". The .xcdatamodel files contain an XML file named "contents" but there doesn't seem to be a version for the previous model:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1811" systemVersion="11G63" minimumToolsVersion="Automatic" macOSVersion="Automatic" iOSVersion="Automatic">
    <entity name="Settings" syncable="YES">
        <attribute name="filterOrderArray" optional="YES" attributeType="Transformable" syncable="YES"/>
    </entity>
    <elements>
        <element name="Settings" positionX="160" positionY="192" width="128" height="60"/>
    </elements>
</model>

I also looked in the project's .xcodeproj file (also a package) and found that the project.pbxproj file contains this:

/* Begin XCVersionGroup section */
        CFE0A83E164F6CF40000C765 /* Filters.xcdatamodeld */ = {
            isa = XCVersionGroup;
            children = (
                CFE0A841164F6D100000C765 /* Filters 1.3.xcdatamodel */,
                CFE0A83F164F6CF40000C765 /* Filters 1.2.xcdatamodel */,
            );
            currentVersion = CFE0A841164F6D100000C765 /* Filters 1.3.xcdatamodel     */;
            path = Filters.xcdatamodeld;
            sourceTree = "<group>";
            versionGroupType = wrapper.xcdatamodel;
        };
/* End XCVersionGroup section */

Again, no previous version information, unless its in those hex strings, but the order of the .xcdatamodel files in Xcode / Project Navigation does seem to be determined by the "children" parameter.

I also discovered that renaming a model version breaks the previous version connection (which indicates it's stored somewhere and isn't just the order of the versions) and initWithContentsOfURL will return a nil model if you do so:

NSManagedObjectModel *model = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL];

So, as far as I can tell, you can't view or change which model a model is based on once it is created. If you need to clean up your model hierarchy you have to effectively start over and recreate each needed version (at least you can copy entities from your old models so you're not entirely starting from scratch).

Was it helpful?

Solution

Adding a new version of your model allows you to make changes to the model. The previous versions are there to allow core data to automatically migrate persistent stores created under earlier versions. If you edit the old versions, this migration breaks. You then start to talk about renaming, which isn't really connected. It doesn't make sense to talk about changing the model a version is based on - its just a new version of the same model.

You can browse through the versions, IIRC, by expanding the disclosure triangle by your model in the project browser, once you have a multi-version model.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top