Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func diskImageDownloader(diskSpaceMB: Int = 100) -> ImageDownloader {
- let diskCapacity = diskSpaceMB * 1024 * 1024
- let diskCache = NSURLCache(memoryCapacity: 0, diskCapacity: diskCapacity, diskPath: "alamofireimage_disk_cache")
- let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
- configuration.URLCache = diskCache
- let downloader = ImageDownloader(configuration: configuration)
- UIImageView.af_sharedImageDownloader = downloader
- return downloader
- }
- func getProfileImage(atURL url: String, onComplete: SRServiceResponse<UIImage> -> Void) {
- guard let imageURL = NSURL(string: url) else
- {
- // TODO: Fail here
- return
- }
- let request = NSURLRequest(URL: imageURL)
- let imageDownloader = self.diskImageDownloader()
- imageDownloader.downloadImage(URLRequest: request) { (response) in
- switch response.result
- {
- case .Success(let image):
- // Do something
- case .Failure(let error):
- // Do something
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement