简体   繁体   中英

Value of type 'Result<Any, AFError>' has no member 'value' (with Xcode 13.2 and AlamoFire 5.4.3)

I'm trying to update an app in Xcode 13.2 with AlamoFire 5.4.3, SwiftyJSON 5.0.1. I was able to get everything working except for the following errors. (Value of type 'Result<Any, AFError>' has no member 'value')

I'm pretty new with Swift and eager to learn. The app worked fine when it was using an older versions of AlamoFire. I didn't write this app originally. Any help would be greatly appreciated. If I can clear up anything please let me know.

James

class func getPatiens(options: String, completion: @escaping (_ status: Bool, _ message:String, _ patientsList: [PatientEntity]) -> Void) {
        
        let url = Common.getRequestURL(action: "PATIENTS", options: options, index: "")
        
        AF.request(url, method: .get, encoding: JSONEncoding.default).responseJSON { (response) in
            switch(response.result) {
            
            case .success(_):

               // ERROR: Value of type 'Result<Any, AFError>' has no member 'value'
               if response.result.value != nil{

                // ERROR: Value of type 'Result<Any, AFError>' has no member 'value'
                let jsonResult = JSON(response.result.value as! [String: Any])
                    
                    let patientsList = jsonResult["results"].array!
                    
                    var arrPatients = [PatientEntity]()
                    
                    for index in 0 ..< patientsList.count {
                        let patient = PatientEntity()
                        
                        patient.p_dol  = patientsList[index]["DOL"].string!
                        patient.p_id   = patientsList[index]["ID"].string!
                        patient.p_name = patientsList[index]["NAME"].string!
                        
                        arrPatients.append(patient)
                    }
                    
                    completion(true, "success", arrPatients)
                }
                break
            
            case .failure(_):
                completion(false, "Server Failed", [])
                break
            }
        }
    }

The error is pretty self explanatory. You are receiving a result enumeration. It contains a Success or a Failure. You are ignoring both of them. What you need is to get their associated values:

To get the success value :

case let .success(value):

To get the failure error :

case let .failure(error):

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM