Skip to content

Instantly share code, notes, and snippets.

@CollectiveHealth-gists
Created August 8, 2017 18:50
Show Gist options
  • Save CollectiveHealth-gists/8daab3214071a1da119a8993578483eb to your computer and use it in GitHub Desktop.
Save CollectiveHealth-gists/8daab3214071a1da119a8993578483eb to your computer and use it in GitHub Desktop.
RxSwift Download Image from Url
URLSession.shared.rx
.response(imageURL)
// subscribe on main thread
.subscribeOn(MainScheduler.sharedInstance)
.subscribe(onNext: { [weak self] data in
// Update Image
self?.imageView.image = UIImage(data: data)
}, onError: {
// Log error
}, onCompleted: {
// animate image view alpha
UIView.animateWithDuration(0.3) {
self.imageView.alpha = 1
}
}).addDisposableTo(disposeBag)
@madson
Copy link

madson commented Mar 11, 2018

Thanxxx!

@StefaniOSApps
Copy link

memory leak on lines 10, 12

@benyoung1024
Copy link

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment