KFSwiftImageLoader
KFSwiftImageLoader is an extremely high-performance, lightweight, and energy-efficient pure Swift async web image loader with memory and disk caching for iOS and Watch.
This is the world's first Watch-optimized async image loader with WKInterfaceImage extensions and intelligent automatic cache handling via WKInterfaceDevice.
Please also check out KFWatchKitAnimations for a great way to record beautiful 60 FPS animations for Watch by recording animations from the iOS Simulator.
Note:
Features
- WKInterfaceImage, UIImageView, UIButton, and MKAnnotationView extensions for asynchronous web image loading.
- Memory and disk cache to prevent downloading images every time a request is made or when the app relaunches, with automatic cache management to optimize resource use.
- Energy efficiency by sending only one HTTP/HTTPS request for image downloads from multiple sources that reference the same URL string, registering them as observers for the request.
- Maximum peformance by utilizing the latest and greatest of modern technologies such as Swift 5.1, URLSession, and GCD.
KFSwiftImageLoader Requirements
- Xcode 11.0+
- iOS 12.0+
- watchOS 6.0+
CocoaPods
To ensure you stay up-to-date with the latest version of KFSwiftImageLoader, it is recommended that you use CocoaPods.
Optimized for CocoaPods 1.8.4+, so you will need to run the following command first:
Add the following to your Podfile
You will need to import KFSwiftImageLoader everywhere you wish to use it:
Example Usage
UIImageView
Yes, it really is that easy. It just works.
In the above example, the inputs "placeholder" and "completion" were ignored, so they default to nil.
We can include them in the following way:
For flexibility, there are several different methods for loading images.
Below are the method signatures for all of them:
WKInterfaceImage
The main difference with the UIImageView extension is the parameter "placeholderName", which requires the placeholder image to be bundled with the Watch app for performance reasons.
UIButton
Again, KFSwiftImageLoader makes it very easy to load images.
In this case, the button uses mostly the same method signature as UIImageView, but it includes two more optional parameters: "isBackground" and "controlState".
"controlState" takes a UIControlState value that is required when setting images for buttons.
"isBackground" simply indicates whether or not the button should use "setBackgroundImage:for:" or "setImage:for:" for image loading.
MKAnnotationView
The methods in the MKAnnotationView extension are exactly the same as those in the UIImageView extension.
KFImageCacheManager
Sample App
Please take a look at the sample app under the Example folder for a clear idea of how to use KFSwiftImageLoader to load images in iOS and Watch.