2

I am writing closure with error handling and below is my code, but I am getting a warning "'catch' block is unreachable because no errors are thrown in 'do' block"

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 ))
                }
            }
    }
}

How to remove this warning and catch errors in my controller?

Jata Ram
  • 21
  • 1
  • 3

0 Answers0