From 0d9cd03bd5f20b2e329f2dc25b02ac3d4d57a0dc Mon Sep 17 00:00:00 2001 From: Kevin Wolkober Date: Mon, 13 Jun 2016 18:54:58 +0800 Subject: [PATCH] Make cached response data return optional --- SKPhotoBrowser/SKCachable.swift | 2 +- SKPhotoBrowser/SKCache.swift | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/SKPhotoBrowser/SKCachable.swift b/SKPhotoBrowser/SKCachable.swift index 3287667..48722cd 100644 --- a/SKPhotoBrowser/SKCachable.swift +++ b/SKPhotoBrowser/SKCachable.swift @@ -15,7 +15,7 @@ public protocol SKImageCacheable: SKCacheable { } public protocol SKRequestResponseCacheable: SKCacheable { - func cachedResponseForRequest(request: NSURLRequest) -> NSCachedURLResponse + func cachedResponseForRequest(request: NSURLRequest) -> NSCachedURLResponse? func storeCachedResponse(cachedResponse: NSCachedURLResponse, forRequest request: NSURLRequest) } diff --git a/SKPhotoBrowser/SKCache.swift b/SKPhotoBrowser/SKCache.swift index f27cda1..d2974b1 100644 --- a/SKPhotoBrowser/SKCache.swift +++ b/SKPhotoBrowser/SKCache.swift @@ -30,10 +30,13 @@ public class SKCache { } public func imageForRequest(request: NSURLRequest) -> UIImage? { - let response = (self.imageCache as! SKRequestResponseCacheable).cachedResponseForRequest(request) - let data = response.data + if let response = (self.imageCache as! SKRequestResponseCacheable).cachedResponseForRequest(request) { + let data = response.data - return UIImage(data: data) + return UIImage(data: data) + } + + return nil } public func setImageData(data: NSData, response: NSURLResponse, request: NSURLRequest) {