On Mon, 17 Dec 2012 17:37:22 -0500, Sean McBride said:

>I created a brand new .xcmappingmodel for version x to y of my
>xcdatamodel.  I don't change anything in the mapping GUI.  I clean.  I
>build.  I write some test code:
>
>NSURL* url = ...App.app/Contents/Resources/VersionXToY.cdm
>mappingModel = [[NSMappingModel alloc] initWithContentsOfURL:url]
>
>for (NSEntityMapping* em in [mappingModel entityMappings])
>{
>               id dn = [em destinationEntityName];
>               id dh = [em destinationEntityVersionHash];
>               NSLog(@"%@ = %@", dn, dh);
>}
>
>I then open up the VersionInfo.plist file within my .app and compare the
>entity hashes.
>
>For most, the VersionInfo.plist matches the hashes extracted from
>the .cdm, but for 2 entities they do not.
>
>How can this be?!  As I said, the xcmappingmodel is freshly created!

Just to follow up on this for the archives...

It turns out to be a bug in Xcode's GUI, which I filed as:

<rdar://13073236> Xcode relationship editor shouldn't toggle 'minimum' when 
toggling 'optional'

---------------------
Summary:
Xcode's Core Data relationship editor should *not* toggle the 'minimum' 
checkbox when toggling the 'optional'  checkbox because doing so breaks Core 
Data migration.

Details:
- unzip TrivialMigrationTestStartPoint.zip
- open its Xcode project
- notice it has a trivial xcdatamodel with just 2 entities
- each entity has a relationship and they are both non-optional
- now let's say we need to change the model…
- in Xcode:
 - select the xcdatamodel
 - choose Editor > Add Model Version…
 - the xcdatamodeld bundle and a Version 2.xcdatamodel are created
 - select the version 2.xcdatamodel
 - select the Person entity's 'department' relationship
 - notice the 'optional' checkbox is off, the 'minimum' checkbox is on, and the 
minimum value is 1.
 - now let's say we want 'department' to be optional. This should be no problem 
for migration, since in old stores it will always be present (since it was 
non-optional)
 - click the optional checkbox
- At this point you have the equivalent of TrivialMigrationTestEndPoint.zip 
(also attached)

Expected:
- 'optional' checkbox should go ON, and other settings *should not change*.

Actual:
- 'optional' checkbox does correctly go ON
- the 'minimum' checkbox is also turned OFF. This is bad, elaboration below.
- (see attached video)

Notes:
- turning off 'minimum' is bad because it results in rdar://13000229.  It 
breaks migration.  An xcmappingmodel built from Version1 and Version2 above 
will have different hashes than the actual xcdatamodels.  It seems that, 
rightly or wrongly, because the minCount is present in the old model but not in 
the new model the hashes are different.
- see also the attached ModelDiff.png which shows the change in the xml 
xcdatamodel

Version1:

        <relationship name="department" minCount="1" maxCount="1" 
deletionRule="Nullify" destinationEntity="Department" inverseName="people" 
inverseEntity="Department" syncable="YES"/>

Version2:

        <relationship name="department" optional="YES" maxCount="1" 
deletionRule="Nullify" destinationEntity="Department" inverseName="people" 
inverseEntity="Department" syncable="YES"/>

The fact that minCount="1" is gone in Version2 is what breaks migration, as per 
rdar://13000229.


Regression:
Occurs in 4.5.2 and 4.6dp4.  Didn't try older.
---------------------

Cheers,

-- 
____________________________________________________________
Sean McBride, B. Eng                 s...@rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to