使用RXSwift时遇到一个非常奇怪的错误。我正在调用的服务是Single trait,当我只打印错误时,我的代码可以毫无问题地进行编译,但是,如果我尝试在“ onError”中执行其他操作,则代码将无法编译。有人有同样的问题吗?
未编译的代码:
NetworkManager.shared.authorizeService(with: parameters)
.subscribe(onSuccess: { [weak self] status in
}, onError: { [weak self] error in
paymentAuthorizationFinishedWithError.onNext(APIResponseError.paymentAlreadyInProgress)
}).disposed(by: bag)
编译的代码:
NetworkManager.shared.authorizeService(with: parameters)
.subscribe(onSuccess: { [weak self] status in
}, onError: { [weak self] error in
print(error)
}).disposed(by: bag)
答案 0 :(得分:2)
快速编译器有时会很慢。特别是在接收方面。问题是这条线
self.paymentAuthorizationFinishedWithError.onNext(APIResponseError.paymentAlreadyInProgress)
由于您使用的是?
参考,因此您忘记添加weak
:
self?.paymentAuthorizationFinishedWithError.onNext(APIResponseError.paymentAlreadyInProgress)