我正在编写带有错误处理的闭包,下面是我的代码,但是我收到一条警告:“'catch'块无法访问,因为在'do'块中未引发任何错误”
enum Result {
case success(r: EmailContentData)
case failure(e: Error)
}
static func getMessageList(index : Int, pageCount: Int, completion : @escaping (Result) -> ())
{
DispatchQueue.global(qos: .userInteractive).async
{
let apiString : String = String(index) + "/" + String(pageCount)
ApiHelper.sharedSession.post(Constant.API.messagelistApi + apiString, postData: NSDictionary(), methodtype: Constant.API.httpGet) { (isError, data, errorDescription) in
guard let data = data else { return }
do {
let result = EmailContentData.init(fromDictionary: data.value(forKey:"data") as! NSDictionary)
completion(Result.success(r: result))
} catch let error {
completion(Result.failure(e: error ))
}
}
}
}
如何删除此警告并在控制器中捕获错误?