1、监测UI变量的变化

return 后把值传递下去。

1.1、输出

[self.usernameTextField.rac_textSignal subscribeNext:^(id x){
NSLog(@"%@", x);
}];

1.2、过滤->输出

[[self.usernameTextField.rac_textSignal
filter:^BOOL(NSString*text){
return text.length > 3;
}]
subscribeNext:^(id x){
NSLog(@"%@", x);
}];

1.3、改变数据类型->过滤->输出

[[[self.usernameTextField.rac_textSignal
map:^id(NSString*text){
return @(text.length);
}]
filter:^BOOL(NSNumber*length){
return[length integerValue] > 3;
}]
subscribeNext:^(id x){
NSLog(@"%@", x);
}];

1.4、subscribeNext的另一种写法

RAC宏允许直接把信号的输出应用到对象的属性上。RAC宏有两个参数,第一个是需要设置属性值的对象,第二个是属性名。每次信号产生一个next事件,传递过来的值都会应用到该属性上

RAC(self.passwordTextField, backgroundColor) =
[validPasswordSignal
map:^id(NSNumber *passwordValid){
return[passwordValid boolValue] ? [UIColor clearColor]:[UIColor yellowColor];
}];

2.常用用法

RAC(self.outputLabel, text) = RACObserve(self.model, name);

3.特殊技巧

3.1切换到主线程

deliverOn:[RACScheduler mainThreadScheduler]]

3.2 重置cell内容

takeUntil:cell.rac_prepareForReuseSignal

3.3 一段时间内没有新信号再往下执行

throttle:0.5

3.4状态改变时发出信号

distinctUntilChanged

3.4空信号

- (RACSignal *)executeSearchSignal
{
return [[[[RACSignal empty] logAll] delay:2.0] logAll];
}
空信号会立即完成。delay操作会将其所接收到的next或complete事件延迟两秒执行。

3.4反转信号

not操作来反转信号
例如:[signal.executing not];

3.4 executionSignals属性(是一个信号)

发送由命令每次执行时生成的信号,创建和发出一个新的命令执行信号执行。

ReactiveCocoa学习笔记--用法的更多相关文章

  1. iOS开发ReactiveCocoa学习笔记(一)

    学习 RAC 我们首先要了解 RAC 都有哪些类 RACSignal RACSubject RACSequence RACMulticastConnection RACCommand 在学习的时候写了 ...

  2. iOS开发ReactiveCocoa学习笔记(六)

    RAC操作方法三. demo地址:https://github.com/SummerHH/ReactiveCocoa.git doNext deliverOn timeout interval del ...

  3. iOS开发ReactiveCocoa学习笔记(四)

    ReactiveCocoa常见操作方法介绍: demo地址:https://github.com/SummerHH/ReactiveCocoa.git 1.1 ReactiveCocoa操作须知 所有 ...

  4. iOS开发ReactiveCocoa学习笔记(五)

    ReactiveCocoa常见操作方法介绍: demo地址:https://github.com/SummerHH/ReactiveCocoa.git filter ignore ignoreValu ...

  5. iOS开发ReactiveCocoa学习笔记(三)

    RAC常用用法: 1.监听按钮的点击事件: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame ...

  6. iOS开发ReactiveCocoa学习笔记(二)

    RAC 中常见的宏: 使用宏定义要单独导入 #import <RACEXTScope.h> 一. RAC(TARGET, [KEYPATH, [NIL_VALUE]]):用于给某个对象的某 ...

  7. ReactiveCocoa学习资料

    ReactiveCocoa 学习资料: ReactiveCocoa入门教程:第一部分 http://www.cocoachina.com/ios/20150123/10994.html Reactiv ...

  8. ReactiveCocoa 学习资料

    之前就有听说,感觉很强大,ReactiveCocoa更加被Mattt Thompson大神称为开启一个新Objective-C纪元.所以觉得非常有学习的必要了. 一些很好的学习资料: Reactive ...

  9. Dynamic CRM 2013学习笔记(二)插件基本用法及调试

      插件是可与 Microsoft Dynamics CRM 2013 和 Microsoft Dynamics CRM Online 集成的自定义业务逻辑(代码),用于修改或增加平台的标准行为.也可 ...

随机推荐

  1. jna

    http://topmanopensource.iteye.com/blog/1752355

  2. Android - Get Bluetooth UUID for this device

    Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join th ...

  3. nginx的RTMP协议服务器

    nginx的RTMP协议服务器 by ahuner 通过以下的配置,可以使nginx接收RTMP流,并在web上播放实时视频. 1.openssl安装 nginx需要http_ssl_module模块 ...

  4. SpringMVC文件上传报错org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

    错误信息: java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to or ...

  5. 鼠标滚轮事件 onmousewheel

    1.fiefox:DOMMouseScroll               detail      detail*(-40)=wheelDelta 除了firefox之外:mousewheel     ...

  6. The 2014 ACMICPC Asia Regional Guangzhou Online

    [A]-_-/// [B]线段树+位运算(感觉可出) [C]地图BFS,找最长线 [D]地图BFS,加上各种复杂情况的最短路-_- [E]-_-/// [F]三分+圆与线段的交点,计算几何 [G]-_ ...

  7. wireshark tls

    想抓一下openfire的包看看,首先要选loopback接口,如果是在本地测试的话. 然后需要搞到rsa私钥,设置好就可以了. keytool -importkeystore -srckeystor ...

  8. svn switch 的用法

    switch用于在同一个版本库内不同分支之间的切换relocate用于版本库访问地址变更时,重新定位版本库 比如,由于SVN服务器更换到另一台主机上,这是SVN服务器的地址改变了,那么各客户端就无法连 ...

  9. CentOS 7.0 安装配置 kafka 消息队列

    查询下载最新版本 kafka http://kafka.apache.org/downloads.html wget http://mirror.bit.edu.cn/apache/kafka/0.8 ...

  10. Bar Chart of Frequency of modals in different sections of the Brown Corpus

    Natural Language Processing with Python Chapter 4.8 colors = 'rgbcmyk' # red, green, blue, cyan, mag ...