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

送分小仙女□ 提交于 2019-12-19 05:59:29

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/13945704/ios-what-is-the-value-expression-function-when-migrating-coredata-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!