Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
//
2
//  ImageCache.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 3/9/22.
6
//
7
 
8
 
9
import UIKit
10
 
11
protocol ImageCache {
12
    subscript(_ url: URL) -> UIImage? { get set }
13
}
14
 
15
struct TemporaryImageCache: ImageCache {
16
    private let cache: NSCache<NSURL, UIImage> = {
17
        let cache = NSCache<NSURL, UIImage>()
18
        cache.countLimit = 100 // 100 items
19
        cache.totalCostLimit = 1024 * 1024 * 600 // 600 MB
20
        return cache
21
    }()
22
 
23
    subscript(_ key: URL) -> UIImage? {
24
        get { cache.object(forKey: key as NSURL) }
25
        set { newValue == nil ? cache.removeObject(forKey: key as NSURL) : cache.setObject(newValue!, forKey: key as NSURL) }
26
    }
27
}