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
NSNumber *transactionAverage = [transactions valueForKeyPath:@"@avg.amount"];
NSNumber *numberOfTransactions = [transactions valueForKeyPath:@"@count"];
NSDate *latestDate = [transactions valueForKeyPath:@"@max.date"];
NSDate *earliestDate = [transactions valueForKeyPath:@"@min.date"];
NSNumber *amountSum = [transactions valueForKeyPath:@"@sum.amount"];
Object Operators
NSArray *payees = [transactions valueForKeyPath:@"@distinctUnionOfObjects.payee"];
NSArray *payees = [transactions valueForKeyPath:@"@unionOfObjects.payee"];
// Important: These operators raise an exception if any of the leaf objects is nil.
Array and Set Operatorsw
NSArray *payees = [arrayOfTransactionsArrays valueForKeyPath:@"@distinctUnionOfArrays.payee"];
NSArray *payees = [arrayOfTransactionsArrays valueForKeyPath:@"@unionOfArrays.payee"];
@distinctUnionOfSets
Important: These operators raise an exception if any of the leaf objects is nil.
Collection Operators的更多相关文章
- iOS之2016面试题一
序言 招聘高峰期来了,大家都非常积极地准备着跳槽,那么去一家公司面试就会有一堆新鲜的问题,可能不会,也可能会,但是了解不够深.本篇文章为群里的小伙伴们去宝库公司的笔试题,由笔者整理并提供笔者个人参考答 ...
- KVC/KVO原理详解及编程指南
一.简介 1.KVC简介 2.KVO简介 二.KVC相关技术 1.Key和Key Path 2.点语法和KVC 3.一对多关系(To-Many)中的集合访问器方法 4.键值验证(Key-Value V ...
- 2016---ios面试题
1.对数组中的元素去重复 例如: 1 2 3 NSArray *array = @[@"12-11", @"12-11", @"12-11&q ...
- ios 消息传递机制
引用文章 一.KVO 1.当对象中的某个属性值发生了改变,可以对这些值的观察者做出通知. 2.接受者(会接收到值发生改变的消息) 必须知道发送者(值将发生改变的那个对象). 3.接收者同样还需要知道发 ...
- KVC与KVO的进阶使用
本篇主要介绍键-值编码KVC,键值观察KVO的进阶使用的一些技巧主要是一下两个方面: KVC的集合操作符 KVO的手动实现方式 KVC集合操作符 关于集合操作符在苹果官方文档搜索Collection ...
- 【转】 KVC/KVO原理详解及编程指南
原文地址:http://blog.csdn.net/wzzvictory/article/details/9674431 前言: 1.本文基本不讲KVC/KVO的用法,只结合网上的资料说说对这种技术的 ...
- 转:KVC/KVO原理详解及编程指南
作者:wangzz 原文地址:http://blog.csdn.net/wzzvictory/article/details/9674431 转载请注明出处 如果觉得文章对你有所帮助,请通过留言或 ...
- KVO 进阶
Key-value coding (KVC) 和 key-value observing (KVO) 是两种能让我们驾驭 Objective-C 动态特性并简化代码的机制.在这篇文章里,我们将接触一些 ...
- Operators一句话介绍(RxJava版)
Cold Observables 在第一个subscriber订阅后才执行事件发送的Observables,默认普通Observables都是这个类型 Cold Observables对于每个订阅的s ...
随机推荐
- 【Todo】Java Queue Stack Vector ArrayList
Java集合框架里存在Queue这个接口,之后有不同类型的队列的实现. 有Stack这个类实现堆栈,其实这个类是通过继承Vector的方式来实现的, Vector和ArrayList的实现方式差不多, ...
- UVa 11988 (数组模拟链表) Broken Keyboard (a.k.a. Beiju Text)
题意: 模拟一个文本编辑器,可以输入字母数字下划线,如果遇到'['则认为是Home键,如果是']'则认作End键. 问最终屏幕上显示的结果是什么字符串. 分析: 如果在数组用大量的移动字符必然很耗时. ...
- 你其实真的不懂print("Hello,world")
http://www.jianshu.com/p/abb55919c453 debugPrint在发布的版本里也 会输出debugPrint只是更倾向于输出对象的调试信息.不管是开发环境还是测试环境都 ...
- java基础:数据类型
一:基本数据类型 (1):整数类型 byte,short,int,long (2):浮点类型 float , double (3):布尔类型 boolean 注意: long 类型的变量后面要 ...
- WM8962 HPOUT 信号强度 时间周期
/*************************************************************************** * WM8962 HPOUT 信号强度 时间周 ...
- php 二维数组的排序
写这是之前一直二维数组排名困扰.自己写的好复杂. 正题: array_mutisort 官方帮助文档 <?php// 取得列的列表foreach ($data as $key => $ro ...
- notepad 行替换使用指南
notepad++是开源的文本处理软件,性能堪比ultraedit,不过在转用notepad++之后一直为他的行替换功能纠结,UE当中只需要用 [^p] 就可以表示一行,但是在notepad++当中, ...
- 剑指offer-第二章排序之年龄排序
题目:对某个公司的人的年龄(0-99)进行排序,该公司的总人数为几万人.要求时间复杂度为O(n),可以辅助O(n)的空间. 思路:实现函数为void SortAge(int ages[],int le ...
- Hadoop学习总结之五:Hadoop的运行痕迹
Hadoop学习总结之五:Hadoop的运行痕迹 Hadoop 学习总结之一:HDFS简介 Hadoop学习总结之二:HDFS读写过程解析 Hadoop学习总结之三:Map-Reduce入门 Ha ...
- Shell教程2-变量
Shell支持自定义变量. 定义变量 定义变量时,变量名不加美元符号($),如: 复制纯文本新窗口 variableName="value" 注意,变量名和等号之间不能有空格, ...