Nuke 10 is extreme in every way. It is faster than the previous version (up to 30% improvement to some operations), more powerful, more ergonomic, and is even easier to learn and use. It brings big additions to the caching infrastructure, great SwiftUI and Combine support, and more ways to adjust the system to fit your needs.
This release is also a massive step-up in the general quality of the framework. It has many improvements to the docs (for example, a complete rewrite of the caching guide), more inline comments, more unit tests (Nuke now has ~100% test coverage with 2x number of lines of code in the test target compared to the main target). It's as reliable as it gets.
Migration. The compiler will assist you with the migration, but if something isn't clear, there is a comprehensive migration guide available.
Switching. Switching from Kingfisher? There is now a dedicated guide available to assist you. There is also one for migrating from SDWebImage.
Caching
- Add
DataCachePolicy
to replace deprecatedDataCacheOptions.storedItems
. The new policy fixes some of the inefficiencies of the previous model and provides more control. For example, one of the additions is an.automatic
policy: for requests with processors, encode and store processed images; for requests with no processors, store original image data. You can learn more about the policies and other caching changes in "Caching: Cache Policy." - Add
ImagePipeline.Cache
with a whole range of convenience APIs for managing cached images: read, write, remove images from all cache layers. - Add
ImagePipeline.Configuration.withDataCache
(aggressive disk cache enabled) andwithURLCache
(HTTP disk cache enabled) to make it easier to set up a pipeline with a configuration you want. Learn more in "Caching: Configuration." - Add
removeAll()
method toImageCaching
andDataCaching
protocols - Add
containsData(for:)
method toDataCaching
andDataCache
which checks if the data exists without bringing it to memory - Add
ImageResponse.CacheType
to address #361 and #435. It defines the source of the retrieved image. - The pipeline no longer stores images fetched using file:// and data:// schemes in the disk cache
ImageCaching
protocols now works with a newImageCacheKey
type (an opaque container) instead ofImageRequest
. If you are providing a custom implementation of theImageCaching
protocol, it needs to be updated. It is now easier because there is no need to come up with a key.
NukeUI (Beta)
NukeUI is a new Swift package. It is a comprehensive solution for displaying lazily loaded images on Apple platforms. The library contains two types:
LazyImage
for SwiftUILazyImageView
for UIKit and AppKit
Both views have an equivalent sets of APIs.
The library uses Nuke for loading images and has many customization options. It also supports GIF rendering thanks to Gifu. GIF is not the most efficient format, so NukeUI also supports playing short videos out of the box.
struct ContainerView: View {
var body: some View {
LazyImage(source: "https://example.com/image.jpeg")
.placeholder { Image("placeholder") }
.transition(.fadeIn(duration: 0.33))
}
}
SwiftUI
Nuke now has first-class SwiftUI support with FetchImage which is now part of the main repo, no need to install it separately. It also has a couple of new additions:
- Add
result
property (previously you could only access the loaded image) - Add
AnyPublisher
support via a newfunc load<P: Publisher>(_ publisher: P) where P.Output == ImageResponse, P.Failure == ImagePipeline.Error
method. You can use it with a custom publisher created by combining publishers introduced in Nuke 9.6. - Add
ImageRequestConvertible
support
Combine
Nuke 10 goes all-in on Combine. ImagePublisher
was initially introduced in the previous release, Nuke 9.6, and now Combine is supported across the framework.
ImageRequest
now supports Combine Publisher via a new initializerImageRequest(id:data:)
wheredata
is aPublisher
. It can be used in a variety of scenarios, for example, loading data using `PhotosKit.- As mentioned earlier,
FetchImage
now also supports publishers. So when you create a publisher chain, there is now an easy way to display it.
ImageRequest.Options
Nuke 10 has a reworked ImageRequest.Options
option set replacing removed ImageRequestOptions
. The name is similar, but the options are slightly different. The new approach has more options while being optimized for performance. ImageRequest
size in memory reduced from 176 bytes to just 48 bytes (3.7x smaller).
- Deprecate
ImageRequest.CachePolicy
which is now part of the newImageRequest.Options
option set - Remove
filteredURL
, you can now pass it usinguserInfo
and.imageIdKey
key instead. It's a rarely used option, and this is why it is now less visible. - Remove
cacheKey
andloadKey
(hopefully, nobody is using it because these weren't really designed properly). You can now use the new methods ofImagePipeline.Delegate
that allows customizing the keys. - Add more options for granular control over caching and loading. For example,
ImageRequest.Options
has a new.disableDiskCache
option. - Move
userInfo
directly toImageRequest
. It's now easier to pass and it allows the framework to perform some additional optimizations. userInfo
now usesImageRequest.UserInfoKey
wrapper for keys replacingAnyHashable
. The new approach is faster and adds type-safety.
ImagePipeline.Delegate
- Add
ImagePipeline.Delegate
with a variety of advanced per-request customization options that were previously not possible. For example, withdataCache(for:pipeline:)
method you can specify a disk cache for each request. WithwillCache(data:image:for:pipeline:completion:)
you can disable caching per-request or modify the cached data. And there are more. - Deprecated
ImagePipelineObserving
protocol is now fully covered byImagePipeline.Delegate
Performance
ImageRequest
size in memory reduced from 176 bytes to just 48 bytes (3.7x smaller), which is due to the OptionSet usage and also reordering of properties to take advantage of gaps in memory stride. The size of other types was also reduced, but not as dramatically. For example,ImageTask
andImagePipeline.Configuration
now also take a bit less memory- Coalescing now supports even more scenarios. For example, setting
ImageRequest
options
with a cache policy no longer prevents coalescing of data tasks. - The pipeline now performs memory cache lookup of intermediate (not all processors are applied) progressive image previews and apply the remaining processors on demand
- Extend fast track decoding to the disk cache lookup
- For cache policies that require image encoding, encode decompressed images instead of uncompressed ones
Nuke Builder
NukeBuilder is a package that adds a convenience API for creating image requests inspired by SwiftUI. It was updated with support Nuke 10 and some quality-of-life improvements.
- Rename package to NukeBuilder
- Update to Nuke 10.0
- Add
ImageRequestConvertible
support which means it now supports more types:URLRequest
andString
- Add Combine support
- Add
ImagePipeline
typealias for convenience – you only need to importNukeBuilder
in many cases
Other
- Increase minimum required Xcode version to 12; no changes to the supported platforms
Nuke.loadImage()
methods now work with optional image requests. If the request isnil
, it handles the scenario the same way as failure.ImageRequest
now also works with optionalURL
String
now also conforms toImageRequestConvertible
, closes #421- Optional
URL
now also conforms toImageRequestConvertible
- Streamline pipeline callback closures
- Pass failing processor to
ImagePipeline.Error.processingFailed
- Add type-safe
ImageContainer.UserInfoKey
andImageRequest.UserInfoKey
- Pass additional parameter
Data?
tonuke_display
(ImageView extensions) ImagePrefetcher
now always sets the priority of the requests to its priorityImagePrefetcher
now works withImageRequestConvertible
, adding support forURLRequest
andString
ImagePipeline
can now be invalidated withinvalidate()
method
Deprecations
There are deprecation warnings in place to help guide you through the migration process.
- Deprecate
ImageRequestOptions
, useImageRequest.Options
instead (it's not just the name change) - Deprecate
ImagePipelineObserving
, useimageTask(_:,didReceiveEvent)
fromImagePipeline.Delegate
instead - Rename
isDeduplicationEnabled
toisTaskCoalescingEnabled
- Deprecate
animatedImageData
associated object for platform images. Usedata
property ofImageContainer
instead.animatedImageData
was initially soft-deprecated in Nuke 9.0. - Deprecate the default
processors
inImagePipeline
; use the newprocessors
options inImageLoadingOptions
instead - Deprecate
ImageEncoder
andImageDecoder
typealiases.