ReactiveCocoa (RAC) is a Cocoa framework built on top of ReactiveSwift. It provides APIs for using ReactiveSwift with Apple's Cocoa frameworks.
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
There is a bridge to convert between those APIs (ReactiveObjCBridge) which is mostly meant as a compatibility layer for older ReactiveCocoa projects.
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 set the
EMBEDDED_CONTENT_CONTAINS_SWIFTbuild setting to “Yes”.
Make sure to add
Result.framework to "Linked Frameworks and Libraries" and "copy-frameworks" Build Phases.
If you would prefer to use CocoaPods, there are some unofficial podspecs that have been generously contributed by third parties.