Я работаю над расширением alertmessage для UIViewcontroller
, используя RXSwift
.Расширение UIViewController для предупреждения с использованием RXSwift
// UIViewController+Alertmessage
public func observeAlertMessageSignal(alert: Observable<String>) {
let disposeBag = DisposeBag()
alert.observeOn(MainScheduler.instance)
.subscribe(onNext: { message in
self.alertCustomTransitionDelegate = CustomTransitioningDelegate()
let viewModel = AlertViewModel(message: message)
let storyboard = UIStoryboard(name: "Alert", bundle: nil)
let viewController = storyboard.instantiateInitialViewController() as! AlertViewController
viewController.viewModel = viewModel
viewController.delegate = self
viewController.modalPresentationStyle = .custom
viewController.transitioningDelegate = self.alertCustomTransitionDelegate
self.present(viewController, animated: true, completion: nil)
}).addDisposableTo(disposeBag)
}
// ViewModel
--> Declaration of alertObservable in viewModel
var alertObservable = PublishSubject<String>()
--> usage of observable:
transportResponse = active.asObservable()
.filter { $0 }
.flatMap { _ in
return webservice.loadTransport()
}
.catchError { [weak self] e in
if let moyaError = e as? MoyaError {
if case .underlying(let error) = moyaError {
let formattedError = error as NSError
let message = NSError.localizedDescription(error: formattedError)
self?.alertObservable.onNext(message)
}
}
self?.isLoadingObservable.onNext(false)
throw e
}
.map { response in
return [TransportData(items: response)]
}
//ViewController:
--> code inside viewDidLoad
self.observeAlertMessageSignal(alert: viewModel.alertObservable)
observeAlertMessageSignal
функция вызывается, но мой AlertViewController не представлена. Любая помощь в этом?
Спасибо!