Documentation/Migrations/Nuke 5 Migration Guide.md
This guide is provided in order to ease the transition of existing applications using Nuke 4.x to the latest APIs, as well as explain the design and structure of new and changed functionality.
Nuke 5 is a relatively small release which removes some of the complexity from the framework. Hopefully it will make contributing to Nuke easier.
One of the major changes is the removal of promisified API as well as Promise itself. Promises were briefly added in Nuke 4 as an effort to simplify async code. The major downsides of promises are complex memory management, extra complexity for users unfamiliar with promises, complicated debugging, performance penalties. Ultimately I decided that promises were adding more problems than they were solving.
Chances are that changes made in Nuke 5 are not going to affect your code.
Promise itself
- Remove promisified API, use simple closures instead. For example,
Loadingprotocol's methodfunc loadImage(with request: Request, token: CancellationToken?) -> Promise<Image>was replaced with a method with a completion closurefunc loadImage(with request: Request, token: CancellationToken?, completion: @escaping (Result<Image>) -> Void). The same applies toDataLoadingprotocol.- Remove
Promiseclass- Remove
PromiseResolution<T>enum- Remove
Responsetypealias- Add
Result<T>enum which is now used as a replacement forPromiseResolution<T>(for instance, inTargetprotocol, etc)
Loading or DataLoading protocols you should update them to a new closure-based APIs.PromiseResolution<T> with Result<T> where necessary (custom Target conformances, custom Manager.Handler).Manager
- Remove memory cache from
LoaderManagernow not only reads, but also writes toCacheManagernow has new methods to load images w/o target (Nuke 5.0.1)
Loader and you're not using it directly this change doesn't affect youLoader directly and rely on its memory caching, please use the new Manager APIs that load images w/o targetLoader but don't use it directly then simply update to a new initializer which no longer requires you to pass memory cache inDataCaching and CachingDataLoaderDataLoader by yourself. For more info see Third Party Libraries: Using Other Caching Libraries.Make sure that you take those minor changes into account to:
Loaderconstructor now provides a default value forDataDecodingobjectDataLoadingprotocol now works with aNuke.Requestand notURLRequestin case some extra info fromURLRequestis required- Reduce default
URLCachedisk capacity from 200 MB to 150 MB- Reduce default
maxConcurrentOperationCountofDataLoaderfrom 8 to 6.- Shared objects (like
Manager.shared) are now constants.Preheateris now initialized withManagerinstead ofLoadingobject