이번 과제하면서 네트워크에서 이미지를 불러와서 앱에서 표시하는 작업을 할때 Kingfisher를 사용하게 되어 알아보려고 한다. Kingfisher는 Swift로 작성된 강력하고 사용하기 쉬운 라이브러리로 이미지 다운로드와 캐싱을 간단하게 처리할 수 있도록 도와준다
imageView.kf.setImage(with: URL(string: "https://example.com/image.png"))
imageView.kf.setImage(
with: URL(string: "https://example.com/image.png"),
placeholder: UIImage(named: "placeholder")
)
// 기본 이미지 로드
import Kingfisher
let url = URL(string: "https://example.com/image.png")
imageView.kf.setImage(with: url)
//플레이스홀더 이미지와 오류 처리
let url = URL(string: "https://example.com/image.png")
imageView.kf.setImage(
with: url,
placeholder: UIImage(named: "placeholder"),
options: nil,
completionHandler: { result in
switch result {
case .success(let value):
print("Image loaded successfully: \(value.image)")
case .failure(let error):
print("Error loading image: \(error.localizedDescription)")
}
}
)
//이미지 변환 적용
imageView.kf.setImage(
with: URL(string: "https://example.com/image.png"),
options: [.processor(RoundCornerImageProcessor(cornerRadius: 20))]
)
https://github.com/onevcat/Kingfisher.git
pod 'Kingfisher'
pod install