Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. func diskImageDownloader(diskSpaceMB: Int = 100) -> ImageDownloader {
  2.  
  3. let diskCapacity = diskSpaceMB * 1024 * 1024
  4. let diskCache = NSURLCache(memoryCapacity: 0, diskCapacity: diskCapacity, diskPath: "alamofireimage_disk_cache")
  5. let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
  6. configuration.URLCache = diskCache
  7. let downloader = ImageDownloader(configuration: configuration)
  8. UIImageView.af_sharedImageDownloader = downloader
  9.  
  10. return downloader
  11. }
  12.  
  13. func getProfileImage(atURL url: String, onComplete: SRServiceResponse<UIImage> -> Void) {
  14. guard let imageURL = NSURL(string: url) else
  15. {
  16. // TODO: Fail here
  17. return
  18. }
  19.  
  20. let request = NSURLRequest(URL: imageURL)
  21.  
  22. let imageDownloader = self.diskImageDownloader()
  23.  
  24. imageDownloader.downloadImage(URLRequest: request) { (response) in
  25. switch response.result
  26. {
  27. case .Success(let image):
  28. // Do something
  29. case .Failure(let error):
  30. // Do something
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement