how can I get the data of cached images SDWebImage

后端 未结 1 956
轮回少年
轮回少年 2021-02-15 01:03

I\'m using SDWebImage library to cache web images in my UICollectionView:

cell.packItemImage.sd_setImage(with: URL(string: smileImageUrl[indexPath.row]))
         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-02-15 01:33

    SDWebImage caches downloaded images automatically by default. You can use SDImageCache to retrieve images from the cache. There is a memory cache for the current app session, which will be quicker, and there is the disk cache. Example usage:

    if let image = SDImageCache.shared().imageFromDiskCache(forKey: imageURL.absoluteString) {
    //use image
    }
    
    if let image = SDImageCache.shared().imageFromMemoryCache(forKey: imageURL.absoluteString) {
    //use image
    }
    

    Also make sure you import SDWebImage in your file. (If you're using Swift/Carthage, it will be import WebImage

    0 讨论(0)
提交回复
热议问题