Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Commit

Permalink
add image extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Russell Stephens committed Jul 21, 2017
1 parent 63ead6e commit 9469ca3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Snail/Extensions/URLSessionExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ extension URLSession {
task.resume()
return observer
}

public func image(request: URLRequest) -> Observable<(UIImage, URLResponse)> {
let observer = Replay<(UIImage, URLResponse)>(1)
data(request: request).subscribe(queue: .main, onNext: { data, response in
guard let image = UIImage(data: data) else {
observer.on(.error(ErrorType.invalidData))
return
}
observer.on(.next(image, response))
observer.on(.done)
}, onError: { observer.on(.error($0)) })
return observer
}
}

0 comments on commit 9469ca3

Please sign in to comment.