re: Custom Entity Migration Policies - atribute from NSString To NSDate
re: Custom Entity Migration Policies - atribute from NSString To NSDate
- Subject: re: Custom Entity Migration Policies - atribute from NSString To NSDate
- From: Ben Trumbull <email@hidden>
- Date: Mon, 28 Jan 2008 14:21:27 -0800
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden