Alamofire fire variable type has no subscript members

前端 未结 2 1232
忘掉有多难
忘掉有多难 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
            }
        }
    

提交回复
热议问题