Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用RxSwift';s retryWhen运算符提示用户重试或取消_Ios_Swift_Rx Swift - Fatal编程技术网

Ios 使用RxSwift';s retryWhen运算符提示用户重试或取消

Ios 使用RxSwift';s retryWhen运算符提示用户重试或取消,ios,swift,rx-swift,Ios,Swift,Rx Swift,我正在尝试使用MVVM架构制作iOS应用程序。现在我想要的是,如果一个可观测失败,我将向用户显示一个提示,询问他是否想要取消或重试。这对于retryWhen应该足够简单,但从不调用retry。这是我的代码: .retryWhen({ (errorObservable: Observable<Error>) -> Observable<Error> in return promptFor("test", cancelAction: RetryResult.canc

我正在尝试使用
MVVM
架构制作iOS应用程序。现在我想要的是,如果一个可观测失败,我将向用户显示一个提示,询问他是否想要取消或重试。这对于
retryWhen
应该足够简单,但从不调用retry。这是我的代码:

.retryWhen({ (errorObservable: Observable<Error>) -> Observable<Error> in
  return promptFor("test", cancelAction: RetryResult.cancel, actions: [RetryResult.retry])
    .flatMap { action -> Observable<Error> in
      switch action {
      case .retry:
        return errorObservable
      case .cancel:
        return errorObservable.flatMap { Observable.error($0) }
      }
    }
})
.retryWhen({(errorObservable:Observable)->在
返回promptFor(“测试”,取消操作:RetryResult.cancel,操作:[RetryResult.retry])
.flatMap{action->在中可观察
开关动作{
案例。重试:
返回误差可观测
案例。取消:
返回errorObservable.flatMap{Observable.error($0)}
}
}
})
prompt只是我从RxSwiftExample中获取的一种方法,可以在repo中找到,但为了方便起见,它是:

func promptFor<Action : CustomStringConvertible>(_ message: String, cancelAction: Action, actions: [Action]) -> Observable<Action> {
#if os(iOS)
    return Observable.create { observer in
        let alertView = UIAlertController(title: "RxExample", message: message, preferredStyle: .alert)
        alertView.addAction(UIAlertAction(title: cancelAction.description, style: .cancel) { _ in
            observer.on(.next(cancelAction))
        })

        for action in actions {
            alertView.addAction(UIAlertAction(title: action.description, style: .default) { _ in
                observer.on(.next(action))
            })
        }

        (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController?.present(alertView, animated: true, completion: nil)

        return Disposables.create {
            alertView.dismiss(animated:false, completion: nil)
        }
    }
#elseif os(macOS)
    return Observable.error(NSError(domain: "Unimplemented", code: -1, userInfo: nil))
#endif
func promptFor(umessage:String,cancelAction:Action,actions:[Action])->可观察{
#如果操作系统(iOS)
返回可观察的。在中创建{observer
让alertView=UIAlertController(标题:“RxExample”,消息:消息,首选样式:。警报)
addAction(UIAlertAction(标题:cancelAction.description,样式:。cancel){in
观察者打开(.next(取消操作))
})
行动中的行动{
addAction(UIAlertAction(标题:action.description,样式:。默认值){in
观察员:开(.next(action))
})
}
(UIApplication.shared.delegate为!AppDelegate)。窗口?.rootViewController?.present(alertView,动画:true,完成:nil)
归还一次性物品。创建{
alertView.Disclose(动画:false,完成:nil)
}
}
#elseif os(macOS)
返回可观察的错误(N错误(域:“未实现”,代码:-1,用户信息:nil))
#恩迪夫

有人能解释为什么这不起作用吗?或者甚至提供一个解决方案吗?

你所说的不调用
重试是什么意思?是
retryWhen`not called?
retryWhen
仅在发生错误时调用。你确定错误发生了吗?你所说的不调用
重试是什么意思?是
retryWhen`not called?
retryWhen仅在发生错误时调用。是否确实发生了错误?