RxAlertAction
The convenient way to combine UIAlertController and RxSwift
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
- iOS 11.0+
- Xcode 11
- Swift 5.1
Installation
RxAlertAction is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RxAlertAction'
Usage
enum AlertActionType: String {
case One
case Two
case Three
}
let firstAction = RxAlertAction(title: "first", style: .default, identifier: AlertActionType.One)
let secondAction = RxAlertAction(title: "second", style: .cancel, identifier: AlertActionType.Two)
let thirdAction = RxAlertAction(title: "third", style: .destructive, identifier: AlertActionType.Three)
let alert = UIAlertController(title: "Hello world!", message: nil, preferredStyle: .alert)
alert.addAction(firstAction)
alert.addAction(secondAction)
alert.addAction(thirdAction)
present(alert, animated: true)
Observable.merge(firstAction.asObservable(), secondAction.asObservable(), thirdAction.asObservable())
.take(1)
.subscribe(onNext: { print("Selected: \($0)") })
.disposed(by: bag)
Author
Grzegorz Sagadyn, [email protected]
License
RxAlertAction is available under the MIT license. See the LICENSE file for more info.