Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"'isSuccess' is inaccessible due to 'internal' protection level", AlamoFire not working like before

Im using alamoFire on swift but i came across this problem: "isSuccess' is inaccessible due to 'internal' protection level". I have tried this and i have also tried this, here is my code:

AF.request(jsonURL, method: .get, parameters: parameters).responseJSON { (response) in
       if response.result.isSuccess { //problem is here
            print("Got the info")
            print(response)
            
            let flowerJSON : JSON = JSON(response.result.value!)

            let list = flowerJSON["..."]["..."]["..."].stringValue
            
           print(list)
            
        }
    }
like image 440
Aboud Jbara Avatar asked Sep 06 '25 04:09

Aboud Jbara


1 Answers

result is now of the built-in Result enum type, which means you can do pattern matching on it. Your code can be rewritten as:

AF.request("", method: .get, parameters: [:]).responseJSON { (response) in
    if case .success(let value) = response.result {
        print("Got the info")
        print(response)
        
        let flowerJSON : JSON = JSON(value)
        ...
    }
}

Use a switch statement if you want the error case as well:

switch response.result {
case .success(let value):
    // ...
case .failure(let error):
    // ...
}
like image 128
Sweeper Avatar answered Sep 07 '25 17:09

Sweeper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!