swift3.0 NSCache 简单测试

前端之家收集整理的这篇文章主要介绍了swift3.0 NSCache 简单测试前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

贡献者:赵大财
博客:https://my.oschina.net/zhaodacaiGitHub:https://github.com/dacaizhao
邮箱: dacai_zhao@163.com QQ:327532817
=============================

class ViewController: UIViewController,NSCacheDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        let cache = NSCache<AnyObject,AnyObject>()
        cache.totalCostLimit = 5
        cache.delegate = self
        cache.setObject("hahah" as AnyObject,forKey: "1" as AnyObject,cost: 1)
        print(cache.object(forKey: "1" as AnyObject) ?? "")
        cache.removeObject(forKey: "1" as AnyObject)
        
    }
    
    func cache(_ cache: NSCache<AnyObject,AnyObject>,willEvictObject obj: Any) {
        print("完了")
    }

}
原文链接:https://www.f2er.com/swift/322502.html

猜你在找的Swift相关文章