This repo includes operators for Combine, almost complete re-implementation of CombineCocoa, RxViewController, RxGestures and RxKeyboard libraries and some additional features.
Example
import UIKit
import Combine
import CombineCocoa
import CombineOperators
final class SomeViewModel {
let title = CurrentValueSubject<String, Never>("Title")
let icon = CurrentValueSubject<UIImage?, Never>(nil)
let color = CurrentValueSubject<UIColor, Never>(UIColor.white)
let bool = CurrentValueSubject<Bool, Never>(false)
...
}
class ViewController: UIViewController {
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var iconView: UIImageView!
@IBOutlet private weak var switchView: UISwitch!
let viewModel = SomeViewModel()
...
private func configureSubscriptions() {
viewModel.title ==> titleLabel.cb.text
viewModel.iconView ==> iconView.cb.image
viewModel.bool ==> switchView.cb.isOn
viewModel.color ==> (self, ViewController.setTint)
//or viewModel.color ==> cb.weak(method: ViewController.setTint)
//or viewModel.color ==> {[weak self] in self?.setTint(color: $0) }
}
private func setTint(color: UIColor) {
...
}
...
}
=>
From Publisher
to Subscriber
, creates a subscription:
intPublisher => intSubscriber
- From `Publisher` to `Subject`, creates a subscription and returns `Cancellable`:
```swift
let Cancellable = intPublisher => intSubject
Cancellable
to DisposeBag
:someCancellable => cancellableSet
somePublisher => someSubject => cancellableSet
Publisher
to Scheduler
, returns AnyPublisher<Output, Failure>
:somePublisher => DispatchQueue.main => someSubscriber
Publisher
to (Output) -> Void
:somePublisher => { print($0) }
Publisher
to @autoescaping () -> Void
:somePublisher => print("action")
All operators casts output-input types and errors types where possible
==>
Drive Publisher
to Subscriber
on main queue:
intPublisher ==> intSubscriber => cancellableSet
Operators =>>
and ==>>
replaces .removeDublicates()
CancellableBuilder
and MergeBuilder
, CombineLatestBuilder
- result builders
Some features:
UIView.cb
operators: isVisible
, willAppear
, isOnScreen
, didAppear
, movedToWindow
, frame
, frameOnWindow
, etc.skipNil()
operatoror(Bool), .toggle(), !
operators for boolean sequences+
and +=
operator for merging publishers, creating Cancellables, etcinterval(...)
withLast() -> AnyPublisher<(previous: Output?, current: Output), Failure>
.mp
- @dynamicMemberLookup
mapperasResult() -> AnyPublisher<Result<Output, Failure>, Never>
nilIfEmpty
isEmpty
isNil
isNilOrEmpty
append(...)
smooth(...)
methods to smooth changes, example: sequence[0, 1]
turns to [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
onValue, onFailure, onFinished, onSubscribe, onCancel, onRequest
wrappers on handleEvents(...)
operatorguard()
cb.isFirstResponder
UIStackView().cb.update(...)
UIView().cb.transform.scale(), .rotation(), .translation()
CombineOperators is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'CombineOperators/CombineCocoa'
and run pod update
from the podfile directory first.
Create a Package.swift
file.
// swift-tools-version:5.0
import PackageDescription
let package = Package(
name: "SomeProject",
dependencies: [
.package(url: "https://github.com/dankinsoid/CombineOperators.git", from: "1.81.0")
],
targets: [
.target(name: "SomeProject", dependencies: ["CombineOperators"])
]
)
$ swift build
Voidilov, [email protected]
CombineOperators is available under the MIT license. See the LICENSE file for more info.
link |
Stars: 1 |
Last commit: 44 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics