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 GitHub release Swift 3.0.x 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.values(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" ~> 7.0

If you use Carthage to build your dependencies, make sure you have added ReactiveCocoa.framework, ReactiveSwift.framework, and Result.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', '~> 7.0'

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, Carthage/Checkouts/ReactiveSwift/ReactiveSwift.xcodeproj, and Carthage/Checkouts/Result/Result.xcodeproj into your application’s Xcode project or workspace.
  4. On the “General” tab of your application target’s settings, add ReactiveCocoa.framework, ReactiveSwift.framework, and Result.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 resilence support in Swift 5. Until then, ReactiveCocoa will incrementally adopt new language features.

Github

link
Stars: 18299
Help us keep the lights on

Dependencies

Releases

7.1.0 - Jan 13, 2018

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.0-rc.2 - Dec 24, 2017

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.0-rc.1 - Dec 23, 2017

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 - Nov 24, 2017

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 - Nov 17, 2017

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.