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.
ReactiveCocoa wraps various aspects of Cocoa frameworks with the declarative ReactiveSwift primitives, It provides a rich extension.UI Bindings \ Controls and User Interactions \ Declarative Objective-C Dynamism \ Expressive, Safe Key Path Observation... ...
See [ReactiveCocoa][] for more information.
ReactiveCocoaLocal is a part of the file mirrored from ReactiveCocoa, but ReactiveCocoaLocal exposes the dynamic nature of ReactiveCocoa. So it's convenient to provide extensions for other frameworks including agents, not just Cocoa frameworks. Here's an example of a proxy event extension response for UIImagePickerController:
import UIKit
private class ImagePickerControllerDelegateProxy: DelegateProxy<UIImagePickerControllerDelegate> ,UIImagePickerControllerDelegate {
@objc func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
forwardee?.imagePickerController?(picker, didFinishPickingMediaWithInfo: info)
}
}
extension Reactive where Base: UIImagePickerController {
private var proxy: ImagePickerControllerDelegateProxy {
return .proxy(for: base,
setter: #selector(setter: base.delegate),
getter: #selector(getter: base.delegate))
}
public var pickedMedia: Signal<(picker: UIImagePickerController, info: [UIImagePickerController.InfoKey : Any]), Never> {
return proxy.intercept(#selector(UIImagePickerControllerDelegate.imagePickerController(_:didFinishPickingMediaWithInfo:)))
.map { (picker: $0[0] as! UIImagePickerController, info: $0[1] as! [UIImagePickerController.InfoKey : Any]) }
}
}
use:
let imagePicker = UIImagePickerController.init()
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true) {
imagePicker.reactive.pickedMedia.observe { (event) in
print(" - - -")
}
}
DelegateProxy is not accessible in ReactiveCocoa
It relies on Reactivecocoa and currently only supports manual introduction of ReactiveCocoaLocal