Value Expressions in Mapping Model

in a new model version, the entities of my data model got some additional attributes; among others they got (mandatory) timestamp and identifier fields. The timestamps are of type NSDate, the identifiers are of a custom UUID type that supports the NSCoding protocol whence Core Data can store it as NSData.

Since these attributes are mandatory, I need to assign reasonable values during the migration. For the timestamps, it is ok if every timestamp becomes @[NSDate distantPast]@. The identifiers need to be unique for obvious reasons whence I need to generate for every instance a random identifier, e.g. using the convenience constructor @[UUID uuid]@.

The Mapping Model in XCode lets me define value expressions for the destination entities’ attributes. Unfortunately, I can’t find a comprehensive documentation of the value expression syntax. The Predicate Programming Guide has a section Predicate Format String Syntax but that does not mention the “Function” expression at all.

The NSExpression Class Reference describes the syntax as FUNCTION(receiver, selectorName, arguments, …). Unfortunately, the migration fails to assign proper values if I use the value expressions FUNCTION(NSDate, “distantPast”) and FUNCTION(UUID, “uuid”), respectively - the migration manager complains in the validation phase that the corresponding attributes have no values.

Do you know of additional documentation that may explain what I am doing wrong? Or do you know another approach (short of implementing custom migration managers for every entity) that assigns proper values to the destination entities’ attributes?

I would suggest opening a radar against the documentation for this. It would bring it to the attention of the Core Data team and hopefully they would be able to explain this in better detail. Barring that I would design a custom migration step that is dynamic enough to be written only once but can be injected for each object that has these two mandatory attributes. That would be the simplest path that I can think of.

Actually, someone from apple explained in a dev forum post how to construct the the value expressions. And following that, I opened a documentation enhancement request (#7443740) with Apple asking that they address value expressions in more detail and in just one place.

Of course, such a discussion would also fit very well in your book if you plan to do a 2nd edition. :-)

PS: For those who cannot access the iPhone dev forum: The value expression that calls @[NSDate distantPast]@ is @FUNCTION(CAST(‘NSDate’, ‘Class’), ‘distantPast’)@.