iOS:当迁移coredata关系时,什么是值表达式函数? [英] iOS: what is the value expression function when migrating coredata relationship?
问题描述
关系的函数如下: FUNCTION($ manager,destinationInstancesForEntityMappingNamed:sourceInstances:,employeesToEmployees,$ source.employees)
这个函数是什么?如何调用?是否有任何指南介绍?
阅读Apple的
但我还是没有得到。
这是一个任意方法调用的函数表达式知道是 NSExpression类参考中的一个段落:
函数表达式
在OS X v10.4上,
NSExpression
只支持
预定义的函数集:sum
,count
,min
,max
平均。这些
预定义函数在谓词语法中使用
自定义关键字(例如MAX(1,5,10)
)访问。
在OS X v10.5及更高版本中,函数表达式还支持任意的
方法调用。要使用这个扩展功能,现在
对
使用语法FUNCTION(receiver,selectorName,arguments,...)
/ p>
FUNCTION(@/ Developer / Tools / otest,@lastPathComponent)=> @otest
示例代码中的引用似乎不正确。但是下面的代码在iOS 5/6上编译和运行:
NSExpression * expr = [NSExpression expressionWithFormat:@FUNCTION / Developer / Tools / otest','lastPathComponent')];
id result = [expr expressionValueWithObject:nil context:nil];
NSLog(@result:%@,result);
//输出:
// otest
是一个函数表达式,当被评估时调用
[$ manager destinationInstancesForEntityMappingNamed:@employeesToEmployees
sourceInstances:$ source .employees]
其中 $ manager
code> $ source 替换为迁移管理器和源对象,如映射模型对象。 p>
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.
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
, andaverage
. 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".
这篇关于iOS:当迁移coredata关系时,什么是值表达式函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!