FROM : Ben Trumbull
DATE : Mon Jan 28 23:21:27 2008
Anthony,
You can set the entity migration policy in the mapping model editor in Xcode.
Select the entity in the left hand table view. In the far right hand
inspector, there will be a 'Custom Policy' field. Put the name of
the class for your custom entity policy. In your project, create
such a class as subclass of NSEntityMigrationPolicy.
On your custom subclass, create a method that takes a string and
returns a date. Let's call it:
-(NSDate*)parseString:(NSString)text
In the mapping model, in the middle pane for the property (let's say
it's "time" and it's named the same in the old model) you want to
transform, set the value expression to:
FUNCTION($entityPolicy, "parseString:", $source.time)
This is a predicate expression (documented in Foundation). It says
to call a method on $entityPolicy with the selector "parseString:"
and an argument of $source.time
The $ are the syntax for variable bindings, and the migration process
sets up a context with a few predefined variables set.
$entityPolicy is an instance of your entity policy subclass. $source
is the managed object from the old model. "$source.time" is a
keypath getting the 'time' property from the old model for this
managed object.
--
-Ben
DATE : Mon Jan 28 23:21:27 2008
Anthony,
You can set the entity migration policy in the mapping model editor in Xcode.
Select the entity in the left hand table view. In the far right hand
inspector, there will be a 'Custom Policy' field. Put the name of
the class for your custom entity policy. In your project, create
such a class as subclass of NSEntityMigrationPolicy.
On your custom subclass, create a method that takes a string and
returns a date. Let's call it:
-(NSDate*)parseString:(NSString)text
In the mapping model, in the middle pane for the property (let's say
it's "time" and it's named the same in the old model) you want to
transform, set the value expression to:
FUNCTION($entityPolicy, "parseString:", $source.time)
This is a predicate expression (documented in Foundation). It says
to call a method on $entityPolicy with the selector "parseString:"
and an argument of $source.time
The $ are the syntax for variable bindings, and the migration process
sets up a context with a few predefined variables set.
$entityPolicy is an instance of your entity policy subclass. $source
is the managed object from the old model. "$source.time" is a
keypath getting the 'time' property from the old model for this
managed object.
--
-Ben
| Related mails | Author | Date |
|---|---|---|
| Ben Trumbull | Jan 28, 23:21 | |
| Melissa J. Turner | Jan 28, 23:37 |






Cocoa mail archive

