Swiftpack.co - Package - ReactiveCocoa/ReactiveCocoa

ReactiveCocoa

Reactive extensions to Cocoa frameworks, built on top of ReactiveSwift.

Join the ReactiveSwift Slack community.


Carthage compatible CocoaPods compatible SwiftPM compatible GitHub release Swift 5.1 platforms

⚠️ Looking for the Objective-C API?

🎉 Migrating from RAC 4.x?

🚄 Release Roadmap

What is ReactiveSwift?

ReactiveSwift offers composable, declarative and flexible primitives that are built around the grand concept of streams of values over time. These primitives can be used to uniformly represent common Cocoa and generic programming patterns that are fundamentally an act of observation.

For more information about the core primitives, see ReactiveSwift.

What is ReactiveCocoa?

ReactiveCocoa wraps various aspects of Cocoa frameworks with the declarative ReactiveSwift primitives.

  1. UI Bindings

    UI components expose BindingTargets, which accept bindings from any kind of streams of values via the <~ operator.

    // Bind the `name` property of `person` to the text value of an `UILabel`.
    nameLabel.reactive.text <~ person.name
    

    Note: You'll need to import ReactiveSwift as well to make use of the <~ operator.

  2. Controls and User Interactions

    Interactive UI components expose Signals for control events and updates in the control value upon user interactions.

    A selected set of controls provide a convenience, expressive binding API for Actions.

    // Update `allowsCookies` whenever the toggle is flipped.
    preferences.allowsCookies <~ toggle.reactive.isOnValues
    
    // Compute live character counts from the continuous stream of user initiated
    // changes in the text.
    textField.reactive.continuousTextValues.map { $0.characters.count }
    
    // Trigger `commit` whenever the button is pressed.
    button.reactive.pressed = CocoaAction(viewModel.commit)
    
  3. Declarative Objective-C Dynamism

    Create signals that are sourced by intercepting Objective-C objects, e.g. method call interception and object deinitialization.

    // Notify after every time `viewWillAppear(_:)` is called.
    let appearing = viewController.reactive.trigger(for: #selector(UIViewController.viewWillAppear(_:)))
    
    // Observe the lifetime of `object`.
    object.reactive.lifetime.ended.observeCompleted(doCleanup)
    
  4. Expressive, Safe Key Path Observation

    Establish key-value observations in the form of SignalProducers and DynamicPropertys, and enjoy the inherited composability.

    // A producer that sends the current value of `keyPath`, followed by
    // subsequent changes.
    //
    // Terminate the KVO observation if the lifetime of `self` ends.
    let producer = object.reactive.producer(forKeyPath: #keyPath(key))
    	.take(during: self.reactive.lifetime)
    
    // A parameterized property that represents the supplied key path of the
    // wrapped object. It holds a weak reference to the wrapped object.
    let property = DynamicProperty<String>(object: person,
                                           keyPath: #keyPath(person.name))
    

But there are still more to be discovered and introduced. Read our in-code documentations and release notes to find out more.

Getting started

ReactiveCocoa supports macOS 10.9+, iOS 8.0+, watchOS 2.0+, and tvOS 9.0+.

Carthage

If you use Carthage to manage your dependencies, simply add ReactiveCocoa to your Cartfile:

github "ReactiveCocoa/ReactiveCocoa" ~> 10.1

If you use Carthage to build your dependencies, make sure you have added ReactiveCocoa.framework and ReactiveSwift.framework to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase.

CocoaPods

If you use CocoaPods to manage your dependencies, simply add ReactiveCocoa to your Podfile:

pod 'ReactiveCocoa', '~> 10.1'

Swift Package Manager

If you use Swift Package Manager, simply add ReactiveCocoa as a dependency of your package in Package.swift:

.package(url: "https://github.com/ReactiveCocoa/ReactiveCocoa.git", branch: "master")

Git submodule

  1. Add the ReactiveCocoa repository as a submodule of your application’s repository.
  2. Run git submodule update --init --recursive from within the ReactiveCocoa folder.
  3. Drag and drop ReactiveCocoa.xcodeproj and Carthage/Checkouts/ReactiveSwift/ReactiveSwift.xcodeproj into your application’s Xcode project or workspace.
  4. On the “General” tab of your application target’s settings, add ReactiveCocoa.framework and ReactiveSwift.framework to the “Embedded Binaries” section.
  5. If your application target does not contain Swift code at all, you should also set the EMBEDDED_CONTENT_CONTAINS_SWIFT build setting to “Yes”.

Have a question?

If you need any help, please visit our GitHub issues or Stack Overflow. Feel free to file an issue if you do not manage to find any solution from the archives.

Release Roadmap

Current Stable Release:
GitHub release

In Development

Plan of Record

ABI stability release

ReactiveCocoa is expected to declare library ABI stability when Swift rolls out resilience support in Swift 5. Until then, ReactiveCocoa will incrementally adopt new language features.

Github

link
Stars: 19756

Dependencies

Used By

Total: 0

Releases

10.2.0 - 2020-01-07 15:30:55

Changes

  1. Update ReactiveSwift to 6.2.
  2. Support for Swift Package Manager (#3692, #3676 & #3693, kudos to @fabio-cerdeiral-ck, @sharplet and @simba909)

10.1.0 - 2019-09-26 04:44:15

This is the first minor release of ReactiveCocoa 10. It supports Swift 5.0 (Xcode 10.2/Xcode 10.3) and Swift 5.1 (Xcode 11).

Changes

  • Update dependencies so ReactiveCocoa can be used with Xcode 11 (#3677, kudos to @olejnjak)

Bugfixes

  • Fix crashes of NSObject.signal(for:) and NSObject.producer(for:) with Objective-C enums (#3667, kudos to @gfontenot)

Additions

  • Add a binding target for the barTintColor of UINavigationBar (#3675, kudos to @rehatkathuria)
  • Add reactive extensions for standard WatchKit interface objects. (#3670, kudos to @tdimeco)

10.0.0 - 2019-04-27 22:36:39

This is the first release of ReactiveCocoa 10.0. It supports Xcode 10.2 and Swift 5.0.

Changes

  1. Update ReactiveSwift to 6.0.
  2. Remove dependency on antitypical/Result.

Migration notes

  • If you have used Result only as dependency of ReactiveSwift, remove all instances of import Result, import enum Result.NoError or import struct Result.AnyError and remove the Result Framework from your project.
  • Replace all cases where NoError was used in a Signal or SignalProducer with Never
  • Replace all cases where AnyError was used in a Signal or SignalProducer with Swift.Error

9.0.0 - 2019-03-28 12:38:54

This is the first release of ReactiveCocoa 9.0. It requires Swift 4.2 or above and supports Xcode 10.2/Swift 5.0.

Improvements

  • UITextField and UITextView text and attributedText values non-optional. (#3591, kudos to @Marcocanc)

Additions

  • KVO observations can now be made with Smart Key Path in Swift 3.2+, using producer(for:) and signal(for:) available on NSObject.reactive. (#3491, kudos to @andersio)
  • Binding target for UIApplication.applicationIconBadgeNumber (#3589, kudos to @cocoahero).
  • An extension for NSView.alphaValue. (#3636, kuds to @eimantas)
  • An extension for NSView.isHidden. (#3634, kudos to @eimantas)

8.0.2 - 2018-10-20 14:01:52

This is the second patch release of ReactiveSwift 8.0. It supports Swift 4.1 (Xcode 9.4) and Swift 4.2 (Xcode 10).

Carthage compatibility

A build configuration related issue blocking Carthage builds has been resolved.

Change

  1. ReactiveMapKit has now platform specific build targets and schemes. (#3625, kudos to @andersio)

8.0.1 - 2018-10-06 16:26:39

This is a patch release of ReactiveSwift 8.0. It supports Swift 4.1 (Xcode 9.4) and Swift 4.2 (Xcode 10).

CocoaPods compatibility

The pod spec has been annotated with the language mode ReactiveCocoa is supposed to be built in (Swift 4.1). This should resolve issues when using ReactiveCocoa via CocoaPods with projects in Swift 4.2 mode.

Bugfix

  1. Fixed an issue of SignalProducer.take(duringLifetimeOf:) incorrectly retaining its argument. (#3615, kudos to @andrei-kuzma)

Additions

  1. Add extensions for several properties on WKInterfaceLabel and WKInterfaceButton. (#3616, kudos to @yoching)
  2. Add swift_version to podspecs (#3622, kudos to @olejnjak)
  3. Introduce Lifetime.of(_:) which retrieves the lifetime of any Objective-C or Swift native object. (#3614, kudos to @ra1028)

8.0.0 - 2018-07-25 09:34:25

This is the first release of ReactiveCocoa 8.0. It supports Swift 4.1 (Xcode 9.4) and preliminarily Swift 4.2 (Xcode 10).

Change

  1. Requires ReactiveSwift 4.0.

Additions

  1. Add support for Cocoapods 1.5.0 static frameworks (#3590, kudos to @mishagray)
  2. Add becomeFirstResponder and resignFirstResponder extensions to UIResponder. (#3585, kudos to @Marcocanc)
  3. Added title binding target to UIViewController (#3588, kudos to @cocoahero).
  4. Added several trigger signals for view lifecycle events to UIViewController (#3588, kudos to @cocoahero).
  5. Add extensions for several properties on UIBarButtonItem (#3586, kudos to @asmallteapot).

8.0.0 Release Candidate 1 - 2018-07-04 09:09:40

This is the first release candidate of ReactiveCocoa 8.0. It supports Swift 4.1 (Xcode 9.4) and preliminarily Swift 4.2 (Xcode 10).

Change

  1. Requires ReactiveSwift 4.0 Release Candidate 2.

Additions

  1. Add support for Cocoapods 1.5.0 static frameworks (#3590, kudos to @mishagray)
  2. Add becomeFirstResponder and resignFirstResponder extensions to UIResponder. (#3585, kudos to @Marcocanc)
  3. Added title binding target to UIViewController (#3588, kudos to @cocoahero).
  4. Added several trigger signals for view lifecycle events to UIViewController (#3588, kudos to @cocoahero).

7.2.0 - 2018-04-08 12:50:16

This is the second minor release of ReactiveCocoa 7. It requires ReactiveSwift 3.1, and supports Swift 3.2, 4.0 and 4.1.

Changes

  1. Mitigated a compilation issue specific to Swift 4.1. (#3583)

  2. Fixed a compilation issue related to SR-7299. (#3580)

  3. Improved the interoperability of method interception. (#3570, kudos to @andersio)

Additions

  1. Add showsCancelButton, textDidBeginEditing and textDidEndEditing extensions to UISearchBar (#3565, kudos to @banjun)

  2. NotificationCenter.reactive.keyboard(_:) for system keyboard notification by the event types. (#3566, kudos to @ra1028)

  3. Add extensions for several properties on UINavigationItem (#3576, kudos to @asmallteapot).

7.1.0 - 2018-01-13 17:31:02

This is the first release of ReactiveCocoa 7.1. It requires ReactiveSwift 3.1, and supports Swift 3.2 and Swift 4.0.

Change

  1. Requires ReactiveSwift 3.1.

  2. Fix an issue preventing ReactiveCocoa from being built with the Swift 3.2 language mode. (#3556)

    This issue might affect only users with CocoaPods 1.3.1 and earlier. For Carthage and the Xcode Project users, ReactiveCocoa is always built with the Swift 4.0 language mode.

Addition

  1. Added reactive extension for AppKit's NSTextView. (#3549, kudos to @Palleas)

7.1 Release Candidate 2 - 2017-12-24 16:28:58

This is the second release candidate of ReactiveCocoa 7.1. It requires ReactiveSwift 3.1, and supports Swift 3.2 and Swift 4.0.

Change

  1. Fix an issue preventing ReactiveCocoa from being built with the Swift 3.2 language mode. (#3556)

    This issue might affect only users with CocoaPods 1.3.1 and earlier. For Carthage and the Xcode Project users, ReactiveCocoa is always built with the Swift 4.0 language mode.

7.1 Release Candidate 1 - 2017-12-23 09:03:51

This is the first release candidate of ReactiveCocoa 7.1. It requires ReactiveSwift 3.1, and supports Swift 3.2 and Swift 4.0.

Change

  1. Requires ReactiveSwift 3.1 Release Candidate 1. (#3555)

Addition

  1. Added reactive extension for AppKit's NSTextView. (#3549, kudos to @Palleas)

7.0.1 - 2017-11-24 07:30:12

This is the first maintenance release of ReactiveCocoa 7.0. It supports Swift 3.2 and Swift 4.0.

Bugfix

  1. Fixed DynamicProperty for optional properties. (#3548, kudos to @iv-mexx)

Additions

  1. Added tintColor binding target to UIView. (#3542, kudos to @iv-mexx)

  2. Made makeBindingTarget available on Reactive extensions on all objects, not just NSObject. (#3545, kudos to @Burgestrand)

7.0.0 - 2017-11-17 08:13:27

This is the first release of ReactiveCocoa 7.0. It supports Swift 3.2 and Swift 4.0.

Breaking Change

  1. ReactiveCocoa 7.0 requires ReactiveSwift 3.0 (release note).

  2. DynamicProperty no longer emits optionals. (#3461, kudos to @andersio)

    It now caches the latest value so that even if the underlying object has deinitialised, it would still be able to provide access.

  3. MapKit reactive bindings have been moved to a new ReactiveMapKit framework. (#3524)

    Sources that use the MapKit bindings are now required to import ReactiveMapKit.

    For all Xcode project users (including Carthage), targets need to be configured to link against ReactiveMapKit.

    For CocoaPods users, your Podfile needs to be updated too, since the framework is offered as a standalone pod.

    pod "ReactiveMapKit", "7.0.0-alpha.1"
    

Change

  1. ReactiveCocoa is now compatible with the Swift 4.0 language mode, in addition to the Swift 3.2 compatibility mode. (#3526, kudos to @andersio)

Addition

  1. New convenience:Property(object:keyPath:). (#3461, kudos to @andersio)

    A read-only version of DynamicProperty. Note that this variant is just for untyped key path.

  2. Subscripting reactive with a key path now yields a corresponding BindingTarget under Swift 3.2+. (#3489, kudos to @andersio)

    Example:

    label.reactive[\.text] <~ viewModel.title
    
  3. UISearchBar has gained more reactive bindings and signals. (#3531, kudos to @andersio)

    Signals: Search Button Clicked, Bookmark Button Clicked, Results List Clicked, Selected Scope Button Index

    Binding Target: Selected Scope Button Indices.

7.0.0 Release Candidate 1 - 2017-10-31 08:55:08

This is the second alpha release of ReactiveCocoa 7.0. It supports Swift 3.2 and Swift 4.0.

Breaking Change

  1. DynamicProperty no longer emits optionals. (#3461, kudos to @andersio)

    It now caches the latest value so that even if the underlying object has deinitialised, it would still be able to provide access.

Addition

  1. New convenience:Property(object:keyPath:). (#3461, kudos to @andersio)

    A read-only version of DynamicProperty. Note that this variant is just for untyped key path.

  2. UISearchBar has gained more reactive bindings and signals. (#3531, kudos to @andersio)

    Signals: Search Button Clicked, Bookmark Button Clicked, Results List Clicked, Selected Scope Button Index

    Binding Target: Selected Scope Button Indices.

7.0.0 alpha 2 - 2017-10-20 20:32:51

This is the second alpha release of ReactiveCocoa 7.0. It supports Swift 3.2 and Swift 4.0.

Changes

  1. Requires ReactiveSwift 3.0.0 alpha 1.

  2. ReactiveCocoa is now compatible with the Swift 4.0 language mode, in addition to the Swift 3.2 compatibility mode. (#3526, kudos to @andersio)

7.0.0 alpha 1 - 2017-10-07 08:26:56

This is the first alpha release of ReactiveCocoa 7.0. It targets Swift 3.1, Swift 3.2 and Swift 4.0.

ReactiveMapKit

  1. MapKit reactive bindings have been moved to a new ReactiveMapKit framework. (#3524)

    Sources that use the MapKit bindings are now required to import ReactiveMapKit.

    For all Xcode project users (including Carthage), targets need to be configured to link against ReactiveMapKit.

    For CocoaPods users, your Podfile needs to be updated too, since the framework is offered as a standalone pod.

    pod "ReactiveMapKit", "7.0.0-alpha.1"
    

Special Note on CocoaPods compatibility

As at October 2017, CocoaPods has yet to officially support projects with mixed Swift language modes.

If you fail to build ReactiveCocoa with CocoaPods, you must apply a workaround to override SWIFT_VERSION of ReactiveCocoa as Swift 3.2.

Visit https://github.com/CocoaPods/CocoaPods/issues/6791 for more information.

6.0.2 - 2017-09-21 06:38:00

This is the second maintenance release of ReactiveCocoa 6.0. It targets Swift 3.1, Swift 3.2 and Swift 4.0.

Changes

  1. Disabled code coverage data to allow app submissions with Xcode 9.0 (see https://github.com/Carthage/Carthage/issues/2056, kudos to @NachoSoto)

  2. Improved CocoaPods compatibility when working with Swift 4 projects.

6.1.0 alpha 2 - 2017-09-21 06:32:41

This is the second alpha release of ReactiveCocoa 6.1. It targets Swift 3.1, Swift 3.2 and Swift 4.0.

Change

  1. Improved CocoaPods compatibility when working with Swift 4 projects.

6.1.0 alpha 1 - 2017-09-16 14:15:18

This is the first alpha release of ReactiveCocoa 6.1. It targets Swift 3.1, Swift 3.2 and Swift 4.0.

Change

  1. Disabled code coverage data to allow app submissions with Xcode 9.0 (see https://github.com/Carthage/Carthage/issues/2056, kudos to @NachoSoto)

  2. Updated to ReactiveSwift 2.1.0 alpha 2.

Additions

  1. Added cancelButtonClicked signal to UISearchBar.

  2. Subscripting reactive with a key path now yields a corresponding BindingTarget under Swift 3.2+. (#3489, kudos to @andersio)

    Example:

    label.reactive[\.text] <~ viewModel.title
    

6.0.1 - 2017-08-16 05:53:58

This is the first maintenance release of ReactiveCocoa 6.0. It targets the Xcode 8.3 SDK and Swift 3.1, with preliminary support of the Xcode 9 SDK, Swift 3.2 and Swift 4.0.

Changes

  1. [Xcode 9 beta 5] Fixed an issue causing infinite recursion in the Swift runtime. (#3498, kudos to @andersio)

  2. Update ReactiveSwift to 2.0.1.

    https://github.com/ReactiveCocoa/ReactiveSwift/releases/tag/2.0.1

6.0.0 - 2017-07-21 17:27:53

This is the sixth major release of ReactiveCocoa. It supports Swift 3.1 (Xcode 8.3), and preliminarily supports Swift 3.2 and Swift 4.0 (Xcode 9).

Hightlight

ReactiveSwift 2.0

Please refer to the ReactiveSwift 2.0 release note for more details.

Changes

  1. NSObject reactive extensions now work in generic environments that are limited to NSObjectProtocol. (#3484, kudos to @nickdomenicali)

  2. UIButton.reactive.pressed now reacts to the primaryActionTriggered control event, instead of touchUpInside, on iOS 9.0+ and tvOS 9.0+. (#3480, kudos to @andrei-kuzma)

Additions

  1. New reactive extension for UIScrollView: scrollsToTop. (#3481, kudos to @Qata)

  2. New reactive extension: UITextField.reactive.selectedRangeValues. (#3479, kudos to @Igor-Palaguta)

6.0.0 Release Candidate 3 - 2017-07-12 09:43:20

This is the third release candidate of ReactiveCocoa 6.0. It targets Swift 3.1 with preliminary support of Swift 3.2 and Swift 4.0.

Changes

  1. Updated for ReactiveSwift 2.0.0 Release Candidate 3.

6.0.0 Release Candidate 2 - 2017-07-06 10:08:15

This is the second release candidate of ReactiveCocoa 6.0. It targets Swift 3.1 with preliminary support of Swift 3.2 and Swift 4.0.

Change

  1. Updated for ReactiveSwift 2.0.0 Release Candidate 2.

  2. NSObject reactive extensions now work in generic environments that are limited to NSObjectProtocol. (#3484, kudos to @nickdomenicali)

Addition

  1. New reactive extension for UIScrollView: scrollsToTop. (#3481, kudos to @Qata)

6.0.0 Release Candidate 1 - 2017-06-27 18:52:30

This is the first release candidate of ReactiveCocoa 6.0. It targets Swift 3.1 with preliminary support of Swift 3.2 and Swift 4.0.

Changes

  1. UIButton.reactive.pressed now reacts to the primaryActionTriggered control event, instead of touchUpInside, on iOS 9.0+ and tvOS 9.0+. (#3480, kudos to @andrei-kuzma)

  2. New reactive extension: UITextField.reactive.selectedRangeValues. (#3479, kudos to @Igor-Palaguta)

  3. Updated for ReactiveSwift 2.0 Release Candidate 1.

6.0.0 alpha 1 - 2017-06-12 13:50:28

This is the first alpha release of ReactiveCocoa 6.0. It targets Swift 3.1 with preliminary support of Swift 3.2 and Swift 4.0.

Changes

  1. Updated for ReactiveSwift 2.0 alpha 2.

5.0.4 - 2017-06-09 21:37:59

This is a maintenance release of ReactiveCocoa 5.x. It targets Swift 3.1.

Changes

  1. UITextField text signals now react to editingDidEndOnExit. (#3474)

  2. Introduce mapControlEvents(_:_:) which is set to replace controlEvents(_:_:) in most cases. (#3472)

    You should use mapControlEvents in general unless the state of the control — e.g. text, state — is not concerned. In other words, you should avoid using map on a control event signal to extract the state from the control.

  3. Resigning first responder when reacting to a UITextField signal no longer deadlocks. (#3453, #3472)

  4. New operator: take(duringLifetimeOf:). (#3466, kudos to @andersio) It is available on Signal and SignalProducer, and supports both Objective-C and native Swift objects.

Acknowledgements

Kudos to @mdiep, @sharplet and @andersio who helped review the pull requests and contribute to the documentations.

5.0.3 - 2017-04-08 17:37:05

This is a maintenance release of ReactiveCocoa 5.0. Compatible with Swift 3.0 and 3.1.

Users who use KVO on computed dependent keys are recommended to update to 5.0.3 as soon as possible due to the potential impact of the bug.

Addition

  1. New KVO API: NSObject.reactive(self:).signal(forKeyPath:). (#3413, kudos to @Burgestrand)

  2. New binding targets for UINavigationItem and UITabBarItem. (#3444, kudos to @Marcocanc)

  3. New binding targets for UIFeedbackGenerator and its subclasses. (#3447, kudos to @Marcocanc)

Changes

  1. NSObject.reactive(self:).values(forKeyPath:) is deprecated and replaced by NSObject.reactive(self:).producer(forKeyPath:). (#3413)

  2. The KVO API now supports object values that are of native Swift classes properly. (#3439, kudos to @andersio)

  3. A bug that could lead to deadlocks and unexpected nil in the KVO API on any arbitrary key path was fixed. (#3439)

  4. Continuous text signals of UITextField now emits the latest value for all editing events emitted. In other words, replacements due to autocompletions are now covered by the signals. (#3442 , kudos to @andersio)

  5. Fixed a ObjC swizzling bug that caused ActionProxy not working well with KVO and RAC method interception. (#3435, kudos to @andersio)

Note

The binary was built with Swift 3.1 and ReactiveSwift 1.1.1.

Acknowledgements

Kudos to @mdiep, @NachoSoto, @eimantas, @sharplet, @ikesyo and @andersio who helped review the pull requests and contribute to the documentations.

5.0.2 - 2017-03-30 19:21:10

This is a maintenance release of ReactiveCocoa 5.0. Compatible with Swift 3.0 and 3.1.

Addition

  1. New binding target for UITextField: textColor. (#3410)

Changes

  1. Fixed a bug causing KVO deallocation exception when using values(forKeyPath:) with a nested key path. (#3418)

  2. Fixed a bug causing types with DelegateProxy backed extensions crashed upon deallocation in a specific circumstance. (#3425)

  3. Setting target and action of NSControls no longer disrupts the functionality of its RAC extensions. (#3394)

Note

The binary was built with Swift 3.1 and ReactiveSwift 1.1.1.

5.0.1 - 2017-03-01 07:08:36

This is a maintenance release of ReactiveCocoa 5.0.

Changes

  1. Requires ReactiveSwift 1.1.0.