ReactiveCocoa (RAC) is a Cocoa framework built on top of ReactiveSwift. It provides APIs for using ReactiveSwift with Apple's Cocoa frameworks.
- Example: online search
- Objective-C and Swift
- How does ReactiveCocoa relate to Rx?
- Getting started
If you’re already familiar with functional reactive programming or what ReactiveCocoa is about, check out the Documentation folder for more in-depth information about how it all works. Then, dive straight into our documentation comments for learning more about individual APIs.
This documents the RAC 5 which targets
Swift 3.0.x. For
Swift 2.x support see RAC 4.
ReactiveCocoa is inspired by functional reactive programming.Rather than using mutable variables which are replaced and modified in-place,RAC offers “event streams,” represented by the
SignalProducer types, that send values over time.
Event streams unify all of Cocoa’s common patterns for asynchrony and event handling, including:
- Delegate methods
- Callback blocks
- Control actions and responder chain events
- Futures and promises
- Key-value observing (KVO)
Because all of these different mechanisms can be represented in the same way, it’s easy to declaratively chain and combine them together, with less spaghetti code and state to bridge the gap.
For more information about the concepts in ReactiveCocoa, see ReactiveSwift.
Objective-C and Swift
RAC’s Objective-C API and Swift API are entirely separate, but there is a bridge to convert between the two. This is mostly meant as a compatibility layer for older ReactiveCocoa projects, or to use Cocoa extensions which haven’t been added to the Swift API yet.
The Objective-C API will continue to exist and be supported for the foreseeable future, but it won’t receive many improvements. For more information about using this API, please consult our legacy documentation.
We highly recommend that all new projects use the Swift API.
OS X 10.9+,
watchOS 2.0, and
To add RAC to your application:
- Add the ReactiveCocoa repository as a submodule of your application’s repository.
git submodule update --init --recursivefrom within the ReactiveCocoa folder.
- Drag and drop
Carthage/Checkouts/Result/Result.xcodeprojinto your application’s Xcode project or workspace.
- On the “General” tab of your application target’s settings, add
Result.frameworkto the “Embedded Binaries” section.
- If your application target does not contain Swift code at all, you should also
EMBEDDED_CONTENT_CONTAINS_SWIFTbuild setting to “Yes”.
Or, if you’re using Carthage, simply add ReactiveCocoa to your
Make sure to add
Result.framework to "Linked Frameworks and Libraries" and "copy-frameworks" Build Phases.