Kingfisher
Kingfisher is a lightweight and pure Swift framework for downloading and caching images from the web. It provides a simple way to show images from a remote URL, handle various states while the images are being downloaded, and perform various image operations such as resizing, filtering, and more.
Features
- Download and cache images from the web with ease
- Have placeholder images or activity indicators while downloading
- Handle failure cases and retry downloads if needed
- Apply filters and transformations to images
- Support different image formats, including animated GIFs and WebP
- Manage the caching behavior and memory usage
- Integrate with UIImageView and UIButton for convenience
- Support custom loaders, cache backends, and image processors
- Extensible and customizable architecture
Installation
You can integrate Kingfisher manually, use Swift Package Manager, or CocoaPods dependency manager.
Manual Installation
To manually integrate Kingfisher into your Xcode project, follow these steps:
- Download the latest release version.
- Unzip the downloaded file.
- Drag the “Sources” folder into your Xcode project.
- Make sure “Copy items if needed” is selected.
- Click on your app’s target in Xcode, go to “Build Phases”, and add Kingfisher to “Link Binary with Libraries”.
Swift Package Manager
To integrate Kingfisher using Swift Package Manager:
- In Xcode, go to “File” > “Swift Packages” > “Add Package Dependency”.
- Enter the repository URL (https://github.com/onevcat/Kingfisher.git) and click “Next”.
- Specify the version rules and click “Next”.
- Select the target where you want to add Kingfisher and click “Finish”.
Usage
With Kingfisher, you can easily set image URLs and customize the image view where the image should be displayed. Here is a basic example:
import Kingfisher
let url = URL(string: "https://example.com/image.jpg")
imageView.kf.setImage(with: url)
Advanced Usage
Kingfisher provides various advanced features and customization options. Here are some examples:
Loading Images with Placeholder
You can show a placeholder image while the actual image is being downloaded:
let url = URL(string: "https://example.com/image.jpg")
imageView.kf.setImage(with: url,
placeholder: UIImage(named: "placeholder"))
Loading Images with Completion Handler
You can perform additional tasks once the image is successfully loaded:
let url = URL(string: "https://example.com/image.jpg")
imageView.kf.setImage(with: url) { result in
switch result {
case .success(let value):
// Image successfully loaded, use `value.image` here
case .failure(let error):
// Error occurred while loading the image
}
}
Documentation
For detailed information about Kingfisher and its features, please refer to the official Kingfisher Wiki.
Contributing
Contributions to Kingfisher are welcome! You can report issues, submit pull requests, or suggest new ideas on the official GitHub repository.
License
Kingfisher is released under the MIT license.