WWNetworking-UIImage

main

This is a simple web image downloader, similar to a simple version of SDWebImage or Kingfisher.
William-Weng/WWNetworking-UIImage

WWNetworking-UIImage

Swift-5.6 iOS-14.0 Swift Package Manager-SUCCESS LICENSE

  • This is a simple web image downloader, similar to a simple version of SDWebImage or Kingfisher.
  • 這是一個簡單的網路圖片下載工具,類似SDWebImage或Kingfisher的簡單版本。
  • 使用WWNetworking + WWSQLite3Manager套件來延伸製作,且利用網路圖片的Header-Tag,Last-Modified / ETag,來實現快取功能…

WWNetworking-UIImage

dependencies: [
    .package(url: "https://github.com/William-Weng/WWNetworking-UIImage.git", .upToNextMajor(from: "1.0.0"))
]

可用函式

函式 說明
initDatabase(for:expiredDays:cacheDelayTime:) 初始化資料庫
removeExpiredCacheImages(expiredDays:) 移除過期圖片
downloadImage(with:defaultImage:) 下載圖片
cacheImage(with:) 讀取快取圖片

Example

import UIKit
import WWNetworking_UIImage

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        _ = WWWebImage.initDatabase(for: .documents, expiredDays: 90, cacheDelayTime: 600)
        return true
    }
}
import UIKit
import WWNetworking_UIImage

final class TableViewContrller: UIViewController {

    @IBOutlet weak var myTableView: UITableView!
    
    private let imageUrls = [
        "https://i.pinimg.com/originals/bd/bd/4f/bdbd4f6d85fdaf6c8eea6ffc99aeaa1a.jpg",
        "https://www.niusnews.com/upload/imgs/default/2020Apr_CHOU/0428Sumikko/A1.jpg",
        "https://cc.tvbs.com.tw/img/upload/2020/05/19/20200519191617-75e42ad2.jpg",
        "https://s.yimg.com/ny/api/res/1.2/MubECS_oug7X7MVtm9v9bg--/YXBwaWQ9aGlnaGxhbmRlcjt3PTY0MA--/https://media.zenfs.com/en/dailyview.tw/26023bd61a23e81bf2c4005d03c881a4",
        "https://www.colorsexplained.com/wp-content/uploads/2021/05/shades-of-green-color-infographic.jpg.webp",
        "https://cf.shopee.tw/file/22b1fc845e5ce92481d08c79ffa29296",
        "https://i2.momoshop.com.tw/1658857094/goodsimg/0009/593/640/9593640_O_m.webp",
        "https://hk.rcmart.com/image/catalog/blog_images/sumiko_gurashi_rcmart_charator2.jpg",
        "https://i3.momoshop.com.tw/1672305576/goodsimg/0008/998/717/8998717_O_m.webp",
        "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRmRiFJ6JP4P1rqOcKoIpW9p7UvK8oWmfRcew&usqp=CAU",
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        myTableView.delegate = self
        myTableView.dataSource = self
    }
}

// MARK: - UITableViewDelegate, UITableViewDataSource
extension TableViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return imageUrls.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as? TableViewCell else { fatalError() }
        
        let defaultImage = UIImage(named: "no-pictures")
        
        cell.myLabel?.text = "\(indexPath.row)"
        cell.myImageView.WW.downloadImage(with: imageUrls[indexPath.row], defaultImage: defaultImage)
        
        return cell
    }
}
import UIKit

final class TableViewCell: UITableViewCell {

    @IBOutlet weak var myImageView: UIImageView!
    @IBOutlet weak var myLabel: UILabel!
}

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

Last updated: Mon Apr 15 2024 04:15:51 GMT-0900 (Hawaii-Aleutian Daylight Time)