ios - 如何共享服务器 View 的 viewMode 驱动程序属性?

标签 ios rx-swift

我有一个用于登录的 View 模式。并有一个用于符号结果的变量。我有另一个 View 将根据结果更新 UI,例如成功或失败。

一开始,我想使用单例模式作为 View 模式。但不建议这样做。那么我如何才能为多个 View 订阅相同的 dirve varibale。

var signupResult: Driver<LoginRepository> = Driver.empty()

signupResult = AladdinProvider.rx.request(.login(username: username, password: pwd)).filterSuccessfulStatusCodes().asObservable().mapObject(type: LoginRepository.self).asDriver(onErrorDriveWith: Driver.empty()).

最佳答案

您可以使用 drive 函数订阅驱动程序。

let signupResult = AladdinProvider.rx
    .request(.login(username: username, password: pwd))
    .filterSuccessfulStatusCodes()
    .asObservable() // you likely don't need this operator
    .mapObject(type: LoginRepository.self)
    .asDriver(onErrorDriveWith: Driver.empty())

signupResult
    .drive(onNext: { loginRepository in 
        // set up view for success here.
    })
    .disposed(by: disposeBag)

signupResult
    .drive(onNext: { loginRepository in 
        // set up different view for success here.
    })
    .disposed(by: disposeBag)

关于ios - 如何共享服务器 View 的 viewMode 驱动程序属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57652703/

相关文章:

swift - RxSwift 分页

ios - 使用 Swift 时出现错误 "nil requires a contextual type"

iphone - 将框架转换为库

ios - xCode 不允许添加对象

ios - 无法在 TableView 单元格中显示来自解析的 imageView

ios - RxSwift 网络状态可观察

ios - 如何从 NSPersistentStoreDidImportUbiquitousChangesNotification 获取插入和更新的对象?

ios - 仅在必要时允许 iOS 应用用户通过 Facebook 进行身份验证

swift - 我如何使用 RxSwift 让我的程序快速响应

ios - Rx swift : Mapping a completable to single observable?