RxAlertAction
方便地将 UIAlertController 和 RxSwift 结合在一起
示例
要运行示例项目,请克隆仓库,然后先从 Example 目录运行 pod install
要求
- iOS 11.0+
- Xcode 11
- Swift 5.1
安装
RxAlertAction 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'RxAlertAction'
用法
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)
作者
Grzegorz Sagadyn,[邮箱地址隐藏]
许可证
RxAlertAction 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。