Showing
1 changed file
with
14 additions
and
13 deletions
... | @@ -237,21 +237,22 @@ extension UIImage { | ... | @@ -237,21 +237,22 @@ extension UIImage { |
237 | 237 | ||
238 | } else { | 238 | } else { |
239 | //No cache, so create new one and set image | 239 | //No cache, so create new one and set image |
240 | - let url = URL(string: urlString) | 240 | + if let url = URL(string: urlString) { |
241 | - URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in | 241 | + URLSession.shared.dataTask(with: url, completionHandler: { (data, response, error) in |
242 | - if let error = error { | 242 | + if let error = error { |
243 | - print(error) | 243 | + print(error) |
244 | - return | 244 | + return |
245 | - } | ||
246 | - | ||
247 | - DispatchQueue.main.async(execute: { | ||
248 | - if let downloadedImage = UIImage(data: data!) { | ||
249 | - imageCache.setObject(downloadedImage, forKey: urlString as NSString) | ||
250 | - completion(downloadedImage) | ||
251 | } | 245 | } |
252 | - }) | ||
253 | 246 | ||
254 | - }).resume() | 247 | + DispatchQueue.main.async(execute: { |
248 | + if let downloadedImage = UIImage(data: data!) { | ||
249 | + imageCache.setObject(downloadedImage, forKey: urlString as NSString) | ||
250 | + completion(downloadedImage) | ||
251 | + } | ||
252 | + }) | ||
253 | + | ||
254 | + }).resume() | ||
255 | + } | ||
255 | } | 256 | } |
256 | } | 257 | } |
257 | } | 258 | } | ... | ... |
-
Please register or login to post a comment