首页 > 其他 > 详细

Collection Operators

时间:2014-03-08 20:08:52      阅读:490      评论:0      收藏:0      [点我收藏+]

Collection Operators

  Collection operators are specialized key paths that are passed as the parameter to the valueForKeyPath: method. The operator is specified by a string preceded by an at sign (@). The key path on the left side of the collection operator, if present, determines the array or set, relative to the receiver, that is used in the operation. The key path on the right side of the operator specifies the property of the collection that the operator uses. Figure 1 illustrates the operator key path format.

  bubuko.com,布布扣

  All the collection operators, with the exception of @count, require a key path to the right of the collection operator.

  Note: It is not currently possible to define your own collection operators.

Simple Collection Operators

bubuko.com,布布扣
1 NSNumber *transactionAverage = [transactions valueForKeyPath:@"@avg.amount"];
2 NSNumber *numberOfTransactions = [transactions valueForKeyPath:@"@count"];
3 NSDate *latestDate = [transactions valueForKeyPath:@"@max.date"];
4 NSDate *earliestDate = [transactions valueForKeyPath:@"@min.date"];
5 NSNumber *amountSum = [transactions valueForKeyPath:@"@sum.amount"];
bubuko.com,布布扣

Object Operators

1 NSArray *payees = [transactions valueForKeyPath:@"@distinctUnionOfObjects.payee"];
2 NSArray *payees = [transactions valueForKeyPath:@"@unionOfObjects.payee"];
3  // Important: These operators raise an exception if any of the leaf objects is nil.

Array and Set Operatorsw

bubuko.com,布布扣
1 NSArray *payees = [arrayOfTransactionsArrays valueForKeyPath:@"@distinctUnionOfArrays.payee"];
2 NSArray *payees = [arrayOfTransactionsArrays valueForKeyPath:@"@unionOfArrays.payee"];
3 @distinctUnionOfSets
4 Important: These operators raise an exception if any of the leaf objects is nil.
bubuko.com,布布扣

 

  

Collection Operators,布布扣,bubuko.com

Collection Operators

原文:http://www.cnblogs.com/tekkaman/p/3587721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!