KingFisher란?
1. 비동기 이미지 다운로드 및 캐싱
2. URLSession 기반 네트워킹
3. 메모리와 디스크를 위한 다중 계층 캐시 제공
4. GIF형식의 이미지 지원
5. 유용한 이미지 프로세서 & 필터 기능을 제공
6. Extension 형식으로 기능을 제공
7. SwiftUI도 제공
- PodFile
pod 'Kingfisher', '~> 7.0'
- Swift Packages
https://github.com/onevcat/Kingfisher.git
예제(SwiftUI)
- 기본 설정 가지고 놀기
import SwiftUI
import Kingfisher
struct ContentView: View {
let url:URL = URL(string: "https://randomuser.me/api/portraits/men/50.jpg")!
var body: some View {
VStack{
KFImage(url)
.placeholder {
Image(systemName: "list.dash")
}.retry(maxCount: 3, interval: .seconds(5))
.onSuccess {r in
print("succes: \(r)")
}
.onFailure { e in
print("failure: \(e)")
}
.resizable()
.frame(width: 128, height: 128)
.cornerRadius(20)
.shadow(radius: 5)
}
}
}
}
- 낭비 방지
List {
ForEach(0..<20) { i in
KFImage(URL(string: self.url + "\(i+1).jpg")!)
.cancelOnDisappear(true)
}
}