Last active
May 22, 2022 11:58
-
-
Save mbalex99/8802db1695f20c520ca0 to your computer and use it in GitHub Desktop.
Alamofire and RxSwift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rx_request = Observable<Value>.create { (observer) -> Disposable in | |
let requestReference = Alamofire.request(.POST, url, parameters: payload) | |
.responseJSON(completionHandler: { (response) in | |
if let value = response.result.value { | |
observer.onNext(value) | |
observer.onCompleted() | |
}else if let error = response.result.error { | |
observer.onError(error) | |
} | |
}) | |
return AnonymousDisposable { | |
requestReference.cancel() | |
} | |
} |
How would we use this with alamofire object mapper?
AnonymousDisposable
was deprecated in the latest version. I found this on the changelog:
* Deprecates AnonymousDisposable in favor of Disposables.create(with:)
Replace it with this and it will work:
return Disposables.create(with: { requestReference.cancel() })
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Smart move using the
AnonymousDisposable
to cancel the request 👍