CombineCocoa
CombineCocoa attempts to provide publishers for common UIKit controls so you can consume user interaction as Combine emissions and compose them into meaningful, logical publisher chains.
Note: This is still a primal version of this, with much more to be desired. I gladly accept PRs, ideas, opinions, or improvements. Thank you ! :)
Basic Examples
Check out the Example in the Example folder. Open the project in Xcode 11 and Swift Package Manager should automatically resolve the required dependencies.
Usage
tl;dr:
import Combine
import CombineCocoa
textField.textPublisher // AnyPublisher
segmented.selectedSegmentIndexPublisher // AnyPublisher
slider.valuePublisher // AnyPublisher
button.tapPublisher // AnyPublisher
barButtonItem.tapPublisher // AnyPublisher
switch.isOnPublisher // AnyPublisher
stepper.valuePublisher // AnyPublisher
datePicker.datePublisher // AnyPublisher
refreshControl.isRefreshingPublisher // AnyPublisher
pageControl.currentPagePublisher // AnyPublisher
tapGesture.tapPublisher // AnyPublisher
pinchGesture.pinchPublisher // AnyPublisher
rotationGesture.rotationPublisher // AnyPublisher
swipeGesture.swipePublisher // AnyPublisher
panGesture.panPublisher // AnyPublisher
screenEdgePanGesture.screenEdgePanPublisher // AnyPublisher
longPressGesture.longPressPublisher // AnyPublisher
scrollView.contentOffsetPublisher // AnyPublisher
scrollView.reachedBottomPublisher(offset:) // AnyPublisher
Installation
CocoaPods
Add the following line to your Podfile:
pod 'CombineCocoa'
Swift Package Manager
Add the following dependency to your Package.swift file:
.package(url: "https://github.com/CombineCommunity/CombineCocoa.git", from: "0.2.1")
Carthage
Add the following to your Cartfile:
github "CombineCommunity/CombineCocoa"
Future ideas
- Support non
UIControl.Event
-based publishers (e.g. delegates). - ... your ideas? :)
Acknowledgments
- CombineCocoa is highly inspired by RxSwift's RxCocoa in its essence, kudos to Krunoslav Zaher for all of his amazing work on this.
- Thanks to Antoine van der Lee for his tutorial on Creating Custom Publishers. The idea to set up a control target inside the publisher was inspired by it.
License
MIT, of course ;-) See the LICENSE file.
The Apple logo and the Combine framework are property of Apple Inc.