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. linq to sql DAL

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data. ...

  2. Android蓝牙传感应用(转)

    源:http://www.cnblogs.com/xiaochao1234/p/3753538.html Android手机一般以客户端的角色主动连接SPP协议设备(接上蓝牙模块的数字传感器),连接流 ...

  3. How do JavaScript closures work?

    Like the old Albert Einstein said: If you can't explain it to a six-year-old, you really don't under ...

  4. CALayer 进阶

    转载自:http://www.cofcool.net/development/2015/06/19/ios-study-note-eight-CALayer-info/ The CALayer cla ...

  5. Android安全讲座第九层(二) 内存dump

    近来android上越来越多的应用对自身的保护机制加强了重视,主要表现在几个方面. 1 dex加壳 2 so加壳 3 dex藏在so中,在适当的时候释放. 这是技术上一个进步,并且还有一些专业的公司提 ...

  6. DRAM Memory Rank知识

    DRAM的一些知识点,先记录下来再进行整理 1.何为Memory rank? A memory rank is a set of DRAM chips connected to the same ch ...

  7. UIScrollView 和 UIPageControl

    UIScrollView [滚动视图]非常重要 UIScrollView是滚动视图,是其它带有滚动功能视图的父类, 本身不显示或者只显示背景,主要负责子视图的滚动和翻页. 一.常用属性 1.基本方法 ...

  8. 时间轴CSS的Demo

    一.CSS代码(HTML5支持) /*time-line.css*/ .timeline { position: relative; padding: 20px 0 20px; list-style: ...

  9. hibernate--多对一单向关联 (重点!!!)

    一个用户组包含多个用户, 每个用户属于一个组. 一个人可以有多个车, 每个车属于一个人. 一个人有很多梦想, 一个特定的梦想属于一个人. 错误做法: person里 有 personid, perso ...

  10. ionic系列

    1. 推荐中文API https://github.com/ychow/ionic-guide