Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Ir a la última revisión | | 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(_ key: NSString) -> UIImage? { get set }
13
}
14
 
15
struct TemporaryImageCache: ImageCache {
16
    subscript(key: NSString) -> UIImage? {
17
        get {
18
            cache.object(forKey: key as NSString)
19
        }
20
        set {
21
            newValue == nil ? cache.removeObject(forKey: key as NSString) : cache.setObject(newValue!, forKey: key as NSString)
22
        }
23
    }
24
 
25
    private let cache: NSCache<NSString, UIImage> = {
26
        let cache = NSCache<NSString, UIImage>()
27
        cache.countLimit = 100 // 100 items
28
        cache.totalCostLimit = 1024 * 1024 * 600 // 600 MB
29
        return cache
30
    }()
31
 
32
    /*
33
    subscript(_ key: String) -> UIImage? {
34
        get { cache.object(forKey: key as NSString) }
35
        set { newValue == nil ? cache.removeObject(forKey: key as NSString) : cache.setObject(newValue!, forKey: key as NSString) }
36
    }
37
 */
38
}
39
 
40
 
41
 
42
/*
43
protocol ImageCache {
44
    subscript(_ url: URL) -> UIImage? { get set }
45
}
46
 
47
struct TemporaryImageCache: ImageCache {
48
    private let cache: NSCache<NSURL, UIImage> = {
49
        let cache = NSCache<NSURL, UIImage>()
50
        cache.countLimit = 100 // 100 items
51
        cache.totalCostLimit = 1024 * 1024 * 600 // 600 MB
52
        return cache
53
    }()
54
 
55
    subscript(_ key: URL) -> UIImage? {
56
        get { cache.object(forKey: key as NSURL) }
57
        set { newValue == nil ? cache.removeObject(forKey: key as NSURL) : cache.setObject(newValue!, forKey: key as NSURL) }
58
    }
59
}
60
 */