Database Reference
In-Depth Information
Xcode is being helpful again; it just needs a small nudge from you specifying the
source entity. Since the attribute names match, Xcode will fill in the value
expressions for you. What does it mean to map data from Note entities to
Attachment entities? Think of this as saying, “For each Note, make an Attachment
and copy the image and dateCreated attributes across.”
This mapping will create an Attachment for every Note, but you really only want an
Attachment if there was an image attached to the note. Make sure the
NoteToAttachment entity mapping is selected and in the inspector, set the Filter
Predicate field to image != nil . This will ensure the Attachment mapping will only
happen when there is an image present in the source.
Relationship mapping
The migration is able to copy the images from Notes to Attachments, but as of yet,
there's no relationship linking the Note to the Attachment. The next step to get that
behavior is to add a relationship mapping.
In the NoteToAttachment mapping, you'll see a relationship mapping called note .
Like the relationship mapping you saw in NoteToNote, the value expression is
empty since Xcode doesn't know how to automatically migrate the relationship.
Select the attachment relationship row in the list of relationships so that the
Inspector changes to reflect the properties of the relationship mapping. In the
Source Fetch field, select Auto Generate Value Expression . Enter $source in
the Key Path field and select NoteToNote from the Mapping Name field.
This should generate a value expression that looks like this:
FUNCTION($manager,(
(("destinationInstancesForEntityMappingNamed:sourceInstances:",(
(("NoteToNote",($source)
The FUNCTION statement resembles the objc_msgSend syntax. That is, the first
argument is the object instance, the second argument is the selector and any
further arguments are passed into that method as parameters.
 
Search WWH ::




Custom Search