【发布时间】:2017-06-26 08:50:04
【问题描述】:
我正在关注 RxSwift 示例 GitHub SignUp using Driver,最终得到了类似的结果。
我有一个执行身份验证并返回Observable<AuthenticationResult> 的网络请求,这样我就有了:
public enum AuthenticationResult {
case canceled
case usernameEmpty
case passwordEmpty
case invalidCredentials
case granted(AccessToken)
case other(Error)
}
// Authentication result status
let authenticationResult: Driver<AuthenticationResult>
authenticationResult = input.loginTaps.withLatestFrom(usernameAndPassword)
.flatMapLatest({ (username, password) -> SharedSequence<DriverSharingStrategy, AuthenticationResult> in
return API.authenticate(username: username, password: password, applicationScope: .property).trackActivity(signingIn).asDriver(onErrorJustReturn: .canceled)
})
.flatMapLatest({ (result) -> SharedSequence<DriverSharingStrategy, AuthenticationResult> in
switch result {
case .granted(_):
// The closure is expecting a return value here that I don't have!
let portfoliosNavigationController = UINavigationController(rootViewController: PortfoliosTableViewController())
wireframe.show(viewController: portfoliosNavigationController)
default:
return wireframe.promptFor(result.description, cancelAction: "OK", actions: [])
.map({ (_) -> AuthenticationResult in
result
}).asDriver(onErrorJustReturn: result)
}
})
现在,这是问题:
我的flatMapLatest 期待SharedSequence<DriverSharingStrategy, AuthenticationResult>,但我并不总是返回!
在闭包内,我可以返回SharedSequence<DriverSharingStrategy, AuthenticationResult>如果身份验证成功,因为我的wireframe.promptFor 返回一个可观察的。
但是,当身份验证失败时,我没有可观察的返回。我的 wireframe.show 方法没有返回任何内容。
我该如何处理这种情况?
谢谢
【问题讨论】:
-
身份验证失败时,
API.authenticate会返回什么? -
我得到一个 SharedSequence