Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value of type 'Result<Any, AFError>' has no member 'value' [duplicate]

I am trying to get JSON data from the API & I want to print it on the terminal to check whether I am receiving data on my terminal or not but I am getting this error. I am currently using Swift 5 .

import UIKit
import Alamofire
typealias JSON = [String: Any]

class NetworkingService {
    static let shared = NetworkingService()
    private init() {}

    func getPeople(completion: () -> Void) {
        AF.request("https://launchlibrary.net/1.4/launchstatus").responseJSON{ (response) in

            if let json = response.result.value as? JSON { // here I am getting error
                print(json)
            }
        } 
    }
}
like image 256
Eliza Avatar asked Dec 28 '19 12:12

Eliza


1 Answers

Replace your request completion block with:

switch response.result {
case let .success(value):
    print(value)
case let .failure(error):
    print(error)
}
like image 165
Yonat Avatar answered Nov 20 '22 10:11

Yonat