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

后端 未结 1 1341
终归单人心
终归单人心 2021-01-12 07:38

The function for a relationship is like: FUNCTION($manager, "destinationInstancesForEntityMappingNamed:sourceInstances:","employeesToEmployees",$so

相关标签:
1条回答
  • 2021-01-12 08:14

    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".

    0 讨论(0)
提交回复
热议问题