From 279490444a0335ecd325050db1c670ab46704c92 Mon Sep 17 00:00:00 2001 From: Christian Noon Date: Tue, 15 Sep 2015 22:23:13 -0700 Subject: [PATCH] Image downloader download image completion closures or now optional. 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. --- Source/ImageDownloader.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/ImageDownloader.swift b/Source/ImageDownloader.swift index e2fcafe6..fab999c4 100644 --- a/Source/ImageDownloader.swift +++ b/Source/ImageDownloader.swift @@ -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] @@ -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) } @@ -230,7 +230,7 @@ public class ImageDownloader { public func downloadImage( URLRequest URLRequest: URLRequestConvertible, filter: ImageFilter?, - completion: CompletionHandler) + completion: CompletionHandler?) -> Request? { var request: Request! @@ -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 @@ -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) } } }