Alamofire fire variable type has no subscript members

前端 未结 2 1216
忘掉有多难
忘掉有多难 2020-11-30 14:48

After updating to Alamofire 4 and updating my code to Swift 3, all of my requests are not working for some reason. The variables that I am trying to utilize are highlighted

相关标签:
2条回答
  • 2020-11-30 15:03

    You need to add as? [String: Any]

    Alamofire.request(yourURL).responseJSON { (response) in
            switch response.result {
            case .success:
                if let JSON = response.result.value as? [String: Any] {
                    let message = JSON["message"] as! String
                    print(message)
                }
            case .failure(let error):
                // error handling
            }
        }
    
    0 讨论(0)
  • 2020-11-30 15:25

    I had similar problem, for me solution was to change it as below

    let urladdress = "https://api.github.com/users"
    Alamofire.request(urladdress).responseJSON(completionHandler: {
        response in
        print(response)
    })
    
    0 讨论(0)
提交回复
热议问题