I've been having trouble updating some swift to Alamofire 5. I have read about the how Alamofire moved to the Result type here and how value is not in Alamofire's public interface. Im having trouble getting this into a switch statement as has been recommended. Any help is greatly appreciated.

        AF.request(downloadurl).responseJSON { response in
        let result = response.result

        if let dict = result.value as? Dictionary<String, AnyObject> {
            if let datas = dict["data"] as? [[String:Any]]{
                for data in datas {
                    if let book = data["bookName"] as? String {
                        self._book = book
                    }

                    if let verse = data["text"] as? String {
                        self._verse = verse
                    }

                    if let chapter = data["chapter"] as? String {
                        self._chapter = chapter
                    }
                completed()
                }
            }
        }
    }

1 Answers

1
Alastar On

You can use a simple switch to manage success or failure of your response

switch response.result {
case .success(let json):
   // do what you need
case .failure(let error):
   // do what you need
}