zoukankan      html  css  js  c++  java
  • Collection Operators

    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.

      

      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

    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"];

    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

    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.

      

  • 相关阅读:
    php模拟发送GET和POST请求
    php获取从百度搜索进入网站的关键词
    HDU 6218 (线段树+set)
    Wannafly挑战赛2_D Delete(拓扑序+最短路+线段树)
    BZOJ3926 (后缀自动机)
    Codeforces 848C (cdq分治)
    CERC 2014 (动态树+主席树)
    UOJ 58 (树上带修改的莫队)
    UVA12345 (带修改的莫队)
    BZOJ2038 (莫队)
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3587721.html
Copyright © 2011-2022 走看看