Skip to content

Instantly share code, notes, and snippets.

@linearhw
Last active April 24, 2024 05:29
Show Gist options
  • Save linearhw/796f69ecd77dd41c2fcc81bff3631a04 to your computer and use it in GitHub Desktop.
Save linearhw/796f69ecd77dd41c2fcc81bff3631a04 to your computer and use it in GitHub Desktop.
KingFisher 의 기능 요약/정리

KingFisher

데이터 변환

  • Remote > Data & Image

    • URLSession delegate 의 receiveData 로부터 받은 data 를 모은 다음, UIImage(data: scale:) method 사용
  • Data > toDisk

    • data 의 header 를 읽어서 타입(PNG, JPG, GIF)을 판별
    • 위에서 만든 이미지를 다시 타입에 따라 데이터로 또 만들어 줌 (?)

캐시 저장

기본적인 순서는 아래 이미지 참조

옵션

  • maxCachePeriodInSecond (기본값 1주일)
  • maxMemoryCost (기본값 0. no limit) SDWebImage 와 마찬가지로 역시 NSCache 의 값을 조절한다.
  • maxDiskCacheSize (기본값 0. no limit)
  • cacheMemoryOnly, onlyFromCache, forceRefresh, fromMemoryCacheOrRefresh

메모리 관리

  • memory warning notification 을 받았을 때는 clearMemoryCache 를 호출한다. (memoryCache 에 있는 것들을 전부 지운다.)
  • 앱이 꺼지거나 백그라운드 진입했을 때는 clearExpiredDiskCache 를 호출한다. (expire 된 것들을 지운 다음, 여전히 디스크 용량을 많이 차지하고 있으면 conentAccessDate 로 정렬하여 지운다.)
  • 디스크 캐시 : 기본 Cache Directory + “com.onevcat.Kingfisher.ImageCache” + namespace. 기본값은 "default"

이미지 프로세싱

썸네일 처리

  • 없음 (앞으로 추가될 예정도 없는듯)

그 외의 전처리

  • 다운로드한 다음 캐시하기 전에 image processing 을 하려면 Processor 를 만들어서 적용해야 한다.
let processor = RoundCornerImageProcessor(cornerRadius: 20)
imageView.kf.setImage(with:url, placeholder:nil, options:[.processor(processor)])

GIF 처리

  • 할 수 있다.
  • AnimatedImageView class 를 사용하면 메모리 로드를 줄일 수 있다. 대신 CPU load 가 크다.

기타

  • indicator 이미지를 설정하는 기능도 있음. (GIF도 설정 가능)
  • imageView 에 anigif 를 set 할 때 첫번째 frame 만 불러오도록 하는 기능도 있음
  • SDWebImage 의 light weight pure swift 버전.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment