This file contains hidden or 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
// Consider this function: | |
func fetchPost(by postId: Int, completion: @escaping (Post?, Error?) -> Void) { | |
... | |
} | |
// Using our extension to use an observable | |
// fetchPostObservable looks like: fetchPostObservable(postId) -> Observable<Post> | |
let fetchPostObservable = Observable.fromAsync(postService.getPost(postId:completion:)) | |
// Now to fetch a post you just have to call it just like you would call any function which returns an Observable: | |
fecthPostObservable(10).subscribe(onNext: { (post) in |
OlderNewer