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

Commit

Permalink
Merge pull request #65 from UrbanCompass/image
Browse files Browse the repository at this point in the history
add image extension
  • Loading branch information
Rob Gray authored Jul 21, 2017
2 parents 63ead6e + 9469ca3 commit af00393
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 af00393

Please sign in to comment.