[英]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:我正在使用 Alamofire,在执行获取请求后,我正在处理错误:
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 {
if let error = error as? AFError {
if let error = error as? AFError {
Xcode has a warning: if let error = error as? AFError {
Xcode 有一个警告:
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谢谢
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.因此,
error
保证是一个有效的错误 object - 它不是可选的,所以你根本不需要if let
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.