ReactiveCocoa Tutorial – The Definitive Introduction: Part 1/2

ReactiveCocoa教程——明确的介绍:第一部分(共两部分)

As an iOS developer, nearly every line of code you write is in reaction to some event; a button tap, a received network message, a property change (via Key Value Observing) or a change in user’s location via CoreLocation are all good examples. However, these events are all encoded in different ways; as actions, delegates, KVO, callbacks and others.

作为一个 iOS 开发者,几乎你写的每一个行代码都是在针对某些事件的响应。点击一个按钮、接受一个网络消息、改变一个属性(通过键值观察)或者通过 CoreLoation 改变用户位置都是很好的例子。然而这些事件都是以不同的形式编码,例如动作、代表、键值观察、回调等等。

ReactiveCocoa defines a standard interface for events, so they can be more easily chained, filtered and composed using a basic set of tools.

ReactiveCocoa 给事件定义了一个标准的接口,所以它们可以更容易地连接,过滤并使用一系列基本工具组成。

Sound confusing? Intriguing? … Mind blowing? Then read on :]

听起来很疑惑?有趣?兴奋?还是继续读下去吧☺

ReactiveCocoa combines a couple of programming styles: Functional Programming which makes use of higher order functions, i.e. functions which take other functions as their arguments Reactive Programming which focuses of data-flows and change propagation

ReacticeCocoa 结合了好几种编码风格: ·函数式编程——利用高阶函数,即函数将其它函数作为其参数 ·反应性编程——注重于数据流和改变传播

For this reason, you might hear ReactiveCocoa described as a Functional Reactive Programming (or FRP) framework.

由于这个原因,你可能会听说过ReactiveCocoa被描述成功能反应性编程(FRC)框架。

Rest assured, that is as academic as this tutorial is going to get! Programming paradigms are a fascinating subject, but the rest of this ReactiveCocoa tutorials focuses solely on the practical value, with work-through examples instead of academic theories.

毋庸置疑,这就是本教程预期想要描述的学术知识。编程范式是一个吸引人的话题,但本 ReactiveCocoa 教程的其余部分完全集中于实用价值,用的是实际工作的例子而不是学术理论。

The Reactive Playground

Reactive Playground 应用程序

Throughout this ReactiveCocoa tutorial, you’ll be introducing reactive programming to a very simple example application, the ReactivePlayground. Download the starter project, then build and run to verify you have everything set up correctly.

通过此 ReactiveCocoa 教程,你将会在一个非常简单的示例应用程序即 Reactive Playground 下被引入反应式编程的概念。下载启动项目,然后构建运行来验证你之前一切正确的设置。

ReactivePlayground is a very simple app that presents a sign-in screen to the user. Supply the correct credentials, which are, somewhat imaginatively, user for the username, and password for the password, and you’ll be greeted by a picture of a lovely little kitten.

ReactivePlayground 是一个非常简单的应用程序,给用户提供了一个登录屏幕,提交正确的凭证,多少想象一下,(下面照片中)user输入用户名 password输入密码,接下来你就会被一个可爱的小猫咪照片问候。

Awww! How cute!

哇噢噢噢!多么可爱啊!

Right now it’s a good point to spend a little time looking through the code of this starter project. It is quite simple, so it shouldn’t take long.

好吧现在是一个很好的时机去花点时间去浏览这个启动项目的代码。它是如此简单所以不会占用你多少时间。

Open RWViewController.m and take a look around. How quickly can you identify the condition that results in the enabling of the Sign In button? What are the rules for showing / hiding the signInFailure label? In this relatively simple example, it might take only a minute or two to answer these questions. For a more complex example, you should be able to see how this same type of analysis might take quite a bit longer.

打开 RWViewController.m 文件然后把文件到处浏览一下,你能多快就确定登录按钮所授权允许的登录条件?显示或者隐藏登录失败标签的规则是什么?在这个相对简单的例子中,这个问题只需要一两分钟的时间来回答。相对于更复杂的示例,你可能会需要花费相当长的时间去理解同类型的分析。

With the use of ReactiveCocoa, the underlying intent of the application will become a lot clearer. It’s time to get started!

使用 ReactiveCocoa,底层应用程序将会变得更加清晰可见,是时候开始了!

Adding the ReactiveCocoa Framework

添加ReactiveCocoa框架

The easiest way to add the ReactiveCocoa framework to your project is via CocoaPods. If you’ve never used CocoaPods before it might make sense to follow the Introduction To CocoaPods tutorial on this site, or at the very least run through the initial steps of that tutorial so you can install the prerequisites.

通过 CocoaPods 是给你的项目添加 ReactiveCocoa 框架最简单的方法。如果您以前从未使用过 CocoaPods,那么去学习这个网站介绍 CocoaPods 教程是很有意义的,或者至少浏览该教程教的初始步骤,这样你就可以具备先决条件。

Note: If for some reason you don’t want to use CocoaPods you can still use ReactiveCocoa, just follow the Importing ReactiveCocoa steps in the documentation on GitHub.

注意:如果出于某些原因你不想使用 CocoaPods 你仍然可以使用 ReactiveCocoa,只要按照GitHub文档中导入 ReactiveCocoa 的步骤就行了。

If you still have the ReactivePlayground project open in Xcode, then close it now. CocoaPods will create an Xcode workspace, which you’ll want to use instead of the original project file. Open Terminal. Navigate to the folder where your project is located and type the following:

如果你还有 ReactivePlayground 项目在打开的Xcode中,接着马上关闭它。CocoaPods 将会创建一个你想要用来代替原始项目文件的新的 Xcode 工作区,打开终端。前往你的项目所在的文件夹然后敲入如下命令:

touch Podfile

open -e Podfile

This creates an empty file called Podfile and opens it with TextEdit. Copy and paste the following lines into the TextEdit window:

这将创建一个名为 Podfile 的空文件,然后用 TextEdit 打开它。复制粘贴下面几行到 TextEdit 窗口:

platform :ios, '7.0'

pod 'ReactiveCocoa', '2.1.8'

This sets the platform to iOS, the minimum SDK version to 7.0, and adds the ReactiveCocoa framework as a dependency.

这将设置平台为IOS,要求最低的版本是7.0,并添加 ReactiveCocoa 框架作为一个依赖项。

Once you’ve saved this file, go back to the Terminal window and issue the following command:

一旦你保存这个文件,返回到终端窗口并发出以下命令:

pod install

You should see an output similar to the following:

您应该看到一个类似于下面的输出结果:

Analyzing dependencies

Downloading dependencies

Installing ReactiveCocoa (2.1.8)

Generating Pods project

Integrating client project

[!] From now on use `RWReactivePlayground.xcworkspace`.

This indicates that the ReactiveCocoa framework has been downloaded, and CocoaPods has created an Xcode workspace to integrate the framework into your existing application.

这表明 ReactiveCocoa 框架已经被下载,和 CocoaPods 已经创建了一个集成这个框架到你现有应用程序的 Xcode 工作区。

Open up the newly generated workspace, RWReactivePlayground.xcworkspace, and look at the structure CocoaPods created inside the Project Navigator:

打开新生成的工作区,RWReactivePlayground.xcworkspace 看看 CocoaPods 在项目导航内部创建的结构。

You should see that CocoaPods created a new workspace and added the original project, RWReactivePlayground, together with a Pods project that includes ReactiveCocoa. CocoaPods really does make managing dependencies a breeze!

ReactiveCocoa Tutorial的更多相关文章

  1. ReactiveCocoa入门教程——第一部分

      ReactiveCocoa iOS 翻译    2015-01-22 02:33:37    11471    6    15 本文翻译自RayWenderlich  ReactiveCocoa ...

  2. ReactiveCocoa入门-part2

    ReactiveCocoa是一个框架,它能让你在iOS应用中使用函数响应式编程(FRP)技术.在本系列教程的第一部分中,你学到了如何将标准的动作与事件处理逻辑替换为发送事件流的信号.你还学到了如何转换 ...

  3. ReactiveCocoa入门-part1

    作为一个iOS开发者,你写的每一行代码几乎都是在响应某个事件,例如按钮的点击,收到网络消息,属性的变化(通过KVO)或者用户位置的变化(通过CoreLocation).但是这些事件都用不同的方式来处理 ...

  4. 快快快!27个提升效率的iOS开源库推荐

    文章来源:http://www.csdn.net/article/2015-07-21/2825264-27-ios-open-source-libraries/1 我热爱开源,更喜爱那些花费宝贵的业 ...

  5. 快快快!27个提升效率的iOS开源库推荐(转)

    CSDN移动将持续为您优选移动开发的精华内容,共同探讨移动开发的技术热点话题,涵盖移动应用.开发工具.移动游戏及引擎.智能硬件.物联网等方方面面.如果您想投稿.参与内容翻译工作,或寻求近匠报道,请发送 ...

  6. iOS----精品开源库-开发强力助攻

    30个精品iOS开源库,超强助攻 你不会想错过他们,真的. 我爱开源.  文章的尾部你会看到一个太长不看的版本——一个简单的列表,只有标题和到项目的链接.如果你发现这篇文章是有用的,把它和你的iOS开 ...

  7. iPhone Tutorials

    http://www.raywenderlich.com/tutorials This site contains a ton of fun written tutorials – so many t ...

  8. ReactiveCocoa基础知识内容

    本文记录一些关于学习ReactiveCocoa基础知识内容,对于ReactiveCocoa相关的概念如果不了解可以网上搜索:RACSignal有很多方法可以来订阅不同的事件类型,ReactiveCoc ...

  9. ReactiveCocoa 和 MVVM 入门 (转)

    翻译自ReactiveCocoa and MVVM, an Introduction. 文中引用的 Gist 可能无法显示.为了和谐社会, 请科学上网. MVC 任何一个正经开发过一阵子软件的人都熟悉 ...

随机推荐

  1. Oracel JDBC URL 和 Driver 的获取

    Driver 的获取 Driver Name:   oracle.jdbc.driver.OracleDriver Oracel JDBC URL的获取: URL:   jdbc:oracle:thi ...

  2. CSS 边框

    CSS 边框属性 CSS边框属性允许你指定一个元素边框的样式和颜色. 边框样式 边框样式属性指定要显示什么样的边界.  border-style属性用来定义边框的样式 border-style 值: ...

  3. 343. Integer Break -- Avota

    问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximi ...

  4. centos 6.5 openfire安装

    1.下载:http://igniterealtime.org/downloads/download-landing.jsp?file=openfire/openfire-3.9.3-1.i386.rp ...

  5. javascript判断设备类型-手机(mobile)、安卓(android)、电脑(pc)、其他(ipad/iPod/Windows)等

    使用device.js检测设备并实现不同设备展示不同网页 html代码: <!doctype html> <html> <head> <meta charse ...

  6. 配置nginx支持thinkphp框架

    因为nginx本身没有支持pathinfo,所以无法使用thinkphp框架,不过我们可以在配置里进行修改使其能够正常使用thinkphp. 1.修改配置支持pathinfo vi /etc/ngin ...

  7. linux之GDB常用命令汇总

    查看gdb的版本号 (1)rpm -q gdb 会显示是否安装gdb及版本号 (2)gdb --version也可以 breakpoint b main; b 20; 设置断点 breakpoint ...

  8. u-boot子目录Makefile分析

    一.概述 u-boot的子目录Makefile是整个Makefile体系的重要组成部分,决定了对应子目录的编译过程. 二.分析 以cpu/arm920t/Makefile为例进行说明 (1)首先,调用 ...

  9. GMM+Kalman Filter+Blob 目标跟踪

    转 http://www.cnblogs.com/YangQiaoblog/p/5462453.html ==========图片版================================== ...

  10. c++/MFC 封装好的文件内存映射类

    整理日: 2015年2月16日 首先介绍内存映射文件操作------函数的用法以及先后执行顺序 // 第一步:创建文件 HANDLE hFile = CreateFileForMapping(_T(& ...