iOS: what is the value expression function when migrating coredata relationship?
Asked Answered
K

1

12

The function for a relationship is like: FUNCTION($manager, "destinationInstancesForEntityMappingNamed:sourceInstances:","employeesToEmployees",$source.employees")

What is this "Function"? How will it be called? Is there any guide introducing to this?

I've read Apple's

Core Data Model Versioning and Data Migration programming guide

but I still don't get this.

Kith answered 19/12, 2012 at 4:50 Comment(0)
B
13

This is a "function expressions with arbitrary method invocations" which seem to be very poorly documented. The only reference that I know of is one paragraph in the NSExpression Class Reference:

Function Expressions

On OS X v10.4, NSExpression only supports a predefined set of functions: sum, count, min, max, and average. These predefined functions were accessed in the predicate syntax using custom keywords (for example, MAX(1, 5, 10)).

On OS X v10.5 and later, function expressions also support arbitrary method invocations. To use this extended functionality, you can now use the syntax FUNCTION(receiver, selectorName, arguments, ...), for example:

FUNCTION(@"/Developer/Tools/otest", @"lastPathComponent") => @"otest"

The quoting in that sample code seems be incorrect. But the following code compiles and runs on iOS 5/6:

NSExpression *expr = [NSExpression expressionWithFormat:@"FUNCTION('/Developer/Tools/otest', 'lastPathComponent')"];
id result = [expr expressionValueWithObject:nil context:nil];
NSLog(@"result: %@", result);
// Output:
// otest

So in your case, it is a function expression which calls, when evaluated

[$manager destinationInstancesForEntityMappingNamed:@"employeesToEmployees"
                                    sourceInstances:$source.employees]

where $manager and $source are replaced by the migration manager and the source object, as described in Mapping Model Objects in the "Core Data Model Versioning and Data Migration Programming Guide".

Bullion answered 28/12, 2012 at 10:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.