오픈소스
[open source]Kingfisher
성실농장주
2023. 9. 11. 16:24
Kingfisher
github에서 Kingfisher의 설명을 보면, 순수 swift라이브러리로 웹으로부터 이미지들을 다운로드와 캐싱을하기 위한 라이브러리라고 합니다.
캐싱(caching)이란?
오래 걸리는 작업의 결과물을 임시 저장소에 저장하여 사용했던 데이터를 다시 효율적으로 그리고 빠르게 사용할 수 있게 하는 통신 방식입니다.
앱 개발에서 캐싱 이미지
만약에 웹에서 이미지 url를 가지고 이미지를 다운을 받게 된다면, 요청을 하고 네트워크 환경에 따라 지연이 발생할 수 있습니다.
만약 한번 다운받은 이미지 파일을 로컬 캐시 디렉토리에 저장하게 된다면, 불필요한 네트워크 요청을 줄일 수 있습니다.
Kingfisher 사용 예제
캐시 디렉토리 저장 & 이미지 뷰에 이미지 디스플레이
UIKit에서 Kingfisher 사용
import Kingfisher
let url = URL(string: "https://example.com/image.png")
imageView.kf.setImage(with: url)
SwiftUI에서 Kingfisher 사용
var body: some View {
KFImage(URL(string: "https://example.com/image.png")!)
}
Reference
https://github.com/onevcat/Kingfisher
GitHub - onevcat/Kingfisher: A lightweight, pure-Swift library for downloading and caching images from the web.
A lightweight, pure-Swift library for downloading and caching images from the web. - GitHub - onevcat/Kingfisher: A lightweight, pure-Swift library for downloading and caching images from the web.
github.com