说说ReactiveCocoa 2

- [RACObserve(self, username) subscribeNext: ^(NSString *newName){
- NSLog(@"newName:%@", newName);
- }];
- RAC(self.logInButton, enabled) = [RACSignal
- combineLatest:@[
- self.usernameTextField.rac_textSignal,
- self.passwordTextField.rac_textSignal,
- RACObserve(LoginManager.sharedManager, loggingIn),
- RACObserve(self, loggedIn)
- ] reduce:^(NSString *username, NSString *password, NSNumber *loggingIn, NSNumber *loggedIn) {
- return @(username.length > 0 && password.length > 0 && !loggingIn.boolValue && !loggedIn.boolValue);
- }];
- RACSignal *signal = [RACSignal createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) {
- NSLog(@"triggered");
- [subscriber sendNext:@"foobar"];
- [subscriber sendCompleted];
- return nil;
- }];
- [signal subscribeCompleted:^{
- NSLog(@"subscription %u", subscriptions);
- }];
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"Alert" delegate:nil cancelButtonTitle:@"YES" otherButtonTitles:@"NO", nil];
- [[alertView rac_buttonClickedSignal] subscribeNext:^(NSNumber *indexNumber) {
- if ([indexNumber intValue] == 1) {
- NSLog(@"you touched NO");
- } else {
- NSLog(@"you touched YES");
- }
- }];
- [alertView show];
- [[[self.cancelButton
- rac_signalForControlEvents:UIControlEventTouchUpInside]
- takeUntil:self.rac_prepareForReuseSignal]
- subscribeNext:^(UIButton *x) {
- // do other things
- }];
- voteButton.rac_command = [[RACCommand alloc] initWithEnabled:self.viewModel.voteCommand.enabled signalBlock:^RACSignal *(id input) {
- // Assume that we're logged in at first. We'll replace this signal later if not.
- RACSignal *authSignal = [RACSignal empty];
- if ([[PXRequest apiHelper] authMode] == PXAPIHelperModeNoAuth) {
- // Not logged in. Replace signal.
- authSignal = [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
- @strongify(self);
- FRPLoginViewController *viewController = [[FRPLoginViewController alloc] initWithNibName:@"FRPLoginViewController" bundle:nil];
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
- [self presentViewController:navigationController animated:YES completion:^{
- [subscriber sendCompleted];
- }];
- return nil;
- }]];
- }
- return [authSignal then:^RACSignal *{
- @strongify(self);
- return [[self.viewModel.voteCommand execute:nil] ignoreValues];
- }];
- }];
- [voteButton.rac_command.errors subscribeNext:^(id x) {
- [x subscribeNext:^(NSError *error) {
- [SVProgressHUD showErrorWithStatus:[error localizedDescription]];
- }];
- }];
- [[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"MyNotification" object:nil] subscribeNext:^(NSNotification *notification) {
- NSLog(@"Notification Received");
- }];
- NSArray *array = @[@"foo"];
- [[array rac_willDeallocSignal] subscribeCompleted:^{
- NSLog(@"oops, i will be gone");
- }];
- array = nil;
- - (void)test
- {
- RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
- double delayInSeconds = 2.0;
- dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
- dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
- [subscriber sendNext:@"A"];
- });
- return nil;
- }];
- RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
- [subscriber sendNext:@"B"];
- [subscriber sendNext:@"Another B"];
- [subscriber sendCompleted];
- return nil;
- }];
- [self rac_liftSelector:@selector(doA:withB:) withSignals:signalA, signalB, nil];
- }
- - (void)doA:(NSString *)A withB:(NSString *)B
- {
- NSLog(@"A:%@ and B:%@", A, B);
- }

RAC的作者之一 jspahrsummers 的一个项目
Essentilas: Understanding and Using RACCommand 介绍了RACCommand的使用,同时也涉及了RAC相关的一些点。
OAuth Token Refresh Using ReactiveCocoa 这篇文章讲了如何使用RAC来透明地获取Access Token,然后继续发送请求。
说说ReactiveCocoa 2的更多相关文章
- iOS开发之ReactiveCocoa下的MVVM(干货分享)
最近工作比较忙,但还是出来更新博客了,今天给大家分享一些ReactiveCocoa以及MVVM的一些东西,干活还是比较足的.在之前发表过一篇博文,名字叫做<iOS开发之浅谈MVVM的架构设计与团 ...
- ReactiveCocoa 冷热订阅(cold subscribe, hot subscribe)
ReactiveCocoa支持两种订阅方式,一种是冷订阅,一种是热订阅. 热订阅的特点: 1.不管有没有消息订阅着,发送者总会把消息发出去. 2.不管订阅者是什么时候订阅的,发送者总是会把相同的消息发 ...
- 为什么ReactiveCocoa中推荐使用RACSignal来做信号处理而不是RACSubject
原文解释在这里http://cocoadocs.org/docsets/ReactiveCocoa/0.6.0/ 在标题Creating hot subscribables 底下 先贴原文: The ...
- 最快让你上手ReactiveCocoa之基础篇
前言 很多blog都说ReactiveCocoa好用,然后各种秀自己如何灵活运用ReactiveCocoa,但是感觉真正缺少的是一篇如何学习ReactiveCocoa的文章,这里介绍一下. 1.Rea ...
- [iOS]ReactiveCocoa安装方法
1. 替换Ruby镜像 我们想要使用CocoaPods来安装ReactiveCocoa.由于OS X上的Ruby镜像被墙了,感谢淘宝为我们提供了国内访问镜像. $ gem sources --remo ...
- ReactiveCocoa源码拆分解析(七)
(整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) 在这篇博客中,我将把ReactiveCocoa中的擦 ...
- ReactiveCocoa源码拆分解析(六)
(整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) RAC为了实现优雅的信号绑定,可谓使尽浑身解数,不仅 ...
- ReactiveCocoa源码拆分解析(五)
(整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) 好多天没写东西了,今天继续.主要讲解RAC如何于UI ...
- ReactiveCocoa源码拆分解析(四)
(整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) 上一章节简要的说明了如何实现的热信号.但是像那么写, ...
- ReactiveCocoa源码拆分解析(三)
(整个关于ReactiveCocoa的代码工程可以在https://github.com/qianhongqiang/QHQReactive下载) 这一章节主要讨论信号的“冷”与“热” 在RAC的世界 ...
随机推荐
- sql 条件查询
使用SELECT * FROM <表名>可以查询到一张表的所有记录.但是,很多时候,我们并不希望获得所有记录,而是根据条件选择性地获取指定条件的记录,例如,查询分数在80分以上的学生记录. ...
- 【Codeforces Round #429 (Div. 2) C】Leha and Function
[Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. ...
- IntelliJ IDEA创建Maven web项目速度慢的解决方法
在Properties中添加Name:archetypeCatalog和Value:internal,如下图那样
- host文件是作用
什么是HOST文件:Hosts是一个没有扩展名的系统文件,其基本作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Host ...
- CSS:CSS 组合选择符
ylbtech-CSS:CSS 组合选择符 1.返回顶部 1. CSS 组合选择符 CSS 组合选择符 组合选择符说明了两个选择器直接的关系. CSS组合选择符包括各种简单选择符的组合方式. 在 CS ...
- asp.net core网关Ocelot的简单介绍& Ocelot集成Identity认证
文章简介 Ocelot网关简介 Ocelot集成Idnetity认证处理 Ocelot网关简介 Ocelot是一个基于netcore实现的API网关,本质是一组按特定顺序排列的中间件.Ocelot内 ...
- Perl 换行打印
#!/usr/bin/perl$, = "\t";$\ = "\n"; for($i=0;$i<3;$i++){ print("i: " ...
- 调试Bochs在Linux Mint下面symbol not found的问题
在我的Linux Mint上使用Bochs时出现了很奇怪的问题,按照http://www.cnblogs.com/long123king/p/3568575.html步骤 会提示: symbol no ...
- netif_rx解析
netif_rx函数是在网上收到数据包后,通过中断机制通知CPU而间接调用的中断处理例程. 首先,会将Packet传给netpoll框架,该框架用于在网络协议栈不可用的情况下,也能够提供给内核一个收发 ...
- 转载:vue-cli 脚手架 安装
声明:本文转载自https://www.cnblogs.com/loveyaxin/p/7094089.html 一. node安装 1)如果不确定自己是否安装了node,可以在命令行工具内执行: n ...