Skip to content

Commit

Permalink
Image downloader download image completion closures or now optional.
Browse files Browse the repository at this point in the history
The ability to start a bunch of downloads on the queue prior to actually needing them was not possible before. This is a fairly common use case that is now supported.
  • Loading branch information
cnoon committed Sep 16, 2015
1 parent fa578d5 commit 2794904
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Source/ImageDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class ImageDownloader {
let identifier: String
let request: Request
var filters: [ImageFilter?]
var completionHandlers: [CompletionHandler]
var completionHandlers: [CompletionHandler?]

init(request: Request, filter: ImageFilter?, completion: CompletionHandler) {
init(request: Request, filter: ImageFilter?, completion: CompletionHandler?) {
self.request = request
self.identifier = ImageDownloader.identifierForURLRequest(request.request!)
self.filters = [filter]
Expand Down Expand Up @@ -207,7 +207,7 @@ public class ImageDownloader {
- returns: The created download request if available. `nil` if the image is stored in the image cache and the
URL request cache policy allows the cache to be used.
*/
public func downloadImage(URLRequest URLRequest: URLRequestConvertible, completion: CompletionHandler) -> Request? {
public func downloadImage(URLRequest URLRequest: URLRequestConvertible, completion: CompletionHandler?) -> Request? {
return downloadImage(URLRequest: URLRequest, filter: nil, completion: completion)
}

Expand All @@ -230,7 +230,7 @@ public class ImageDownloader {
public func downloadImage(
URLRequest URLRequest: URLRequestConvertible,
filter: ImageFilter?,
completion: CompletionHandler)
completion: CompletionHandler?)
-> Request?
{
var request: Request!
Expand All @@ -255,7 +255,7 @@ public class ImageDownloader {
withAdditionalIdentifier: filter?.identifier)
{
dispatch_async(dispatch_get_main_queue()) {
completion(URLRequest.URLRequest, nil, .Success(image))
completion?(URLRequest.URLRequest, nil, .Success(image))
}

return
Expand Down Expand Up @@ -305,13 +305,13 @@ public class ImageDownloader {
)

dispatch_async(dispatch_get_main_queue()) {
completion(request, response, .Success(filteredImage))
completion?(request, response, .Success(filteredImage))
}
}
case .Failure:
for completion in responseHandler.completionHandlers {
dispatch_async(dispatch_get_main_queue()) {
completion(request, response, result)
completion?(request, response, result)
}
}
}
Expand Down

0 comments on commit 2794904

Please sign in to comment.