Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Conditional cast from 'AFError' to 'AFError' always succeeds

I’m using Alamofire and after I do the fetch request I’m handling the error with:

guard case let .failure(error) = response.result else { return }

if let error = error as? AFError {
    switch error {
            ...
    }
}

Problem:

In line if let error = error as? AFError { Xcode has a warning:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Conditional cast from 'AFError' to 'AFError' always succeeds

How can I Fix (preferred) or silence that warning?

I tried:

Removing it like this:

if let error = error {

but it says:

Initializer for conditional binding must have Optional type, not 'AFError'

Thanks

>Solution :

You’ve already handled the case where you don’t have an error by returning. Thus, error is guaranteed to be a valid error object – it is not an optional, so you don’t need if let at all.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading