Nuke icon indicating copy to clipboard operation
Nuke copied to clipboard

Undeclared type Response (loadImage) [migration to Nuke 5]

Open YanisSOTO opened this issue 9 years ago • 1 comments

Hi, i've update my pod and i'm performing this error:

Use of undeclared type Response

Here is the code :

ABImageDownloader.sharedInstance .nukeManager .loadImage(with: url, into: strongSelf, handler: { (response: Response, isFromMemoryCache: Bool) in switch(response){ case .fulfilled(let image):

I've tried to change Reponse by DataResponse<Any> but still an error : Cannot invoke 'loadImage' with an argument list of type '(with: URL, into: ABImageView, handler: (DataResponse<Any>, Bool) -> ())'

If you have an idea what i have to change, thank's a lot

YanisSOTO avatar Feb 02 '17 13:02 YanisSOTO

Hey! Nuke 5 is a major release so it does contain some breaking changes.

Here's some information that aims at easing the transition from the previous versions:

Regarding to Response you should replace it with a new Result<T> type. Here's an example:

ABImageDownloader.sharedInstance.nukeManager.loadImage(with: url, into: strongSelf, handler: { (response: Result<Image>, isFromMemoryCache: Bool) in
    switch response {
        case let .success(image): // use image
        case let .failure(error): // handle error
    }
}

You might also want to use trailing closures, and type inference instead of hardcoding concrete types:

ABImageDownloader.sharedInstance.nukeManager.loadImage(with: url, into: strongSelf) { response, isFromMemoryCache in
    switch response {
        case let .success(image): // use image
        case let .failure(error): // handle error
    }
}

kean avatar Feb 02 '17 14:02 kean