1

我已将我的代码更新为 Xcode 10 和 Swift 4.2 ,我遇到了这个错误。额外的论点。我尝试了所有可用的解决方案,但它们可能适用于旧版本的 swift。我正在使用 alamofire 版本:Alamofire 4.7.3,这是我的代码:

func callRemoveUserApi() {
        let token = SharedManager.getAuthenticationToken()
        MBProgressHUD.showAdded(to: self.view, animated: true)
        let headers = [
            "token": token
        ]
        let manager = SharedManager.sharedInstance
        let user = manager.getUpCurrentUser()
        var params = [String:String]()
        params  = [
            "id": user.removed_member!.description,
            "userpath":self.selectedUser.userpath!,
            "path":user.path!
        ]


        Alamofire.request(removeMember, method:.put, parameters: params, encoding: JSONEncoder.default, headers: headers).responseJSON { response in
            print("Request  \(String(describing: response.request))")
            print("RESPONSE \(String(describing: response.result.value))")
            print("RESPONSE \(response.result)")
            print("RESPONSE \(response)")
            switch response.result {
            case .success:
                MBProgressHUD.hide(for: self.view, animated: true)
                var tempResponseDict = response.result.value as! NSDictionary
                // var array = tempResponseDict.object(forKey: "data") as! NSArray
                NotificationCenter.default.post(name: Notification.Name("callMatchesApi"), object: nil)
                self.navigationController?.popViewController(animated: true)
                break
            case .failure( _):
                MBProgressHUD.hide(for: self.view, animated: true)
                break

            }
        }
    }

解决方案: 将 JSONEncoder.default 转换为 JSONEncoding.default 并调用 Alamofire。

Alamofire.request(mobileInfo, method:.put, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
4

1 回答 1

0

标头声明:

 var header : [String:String]?

将值添加到 Header :

   header = [AppConstant.Content:AppConstant.ContentType,
                      AppConstant.Authorization : UserDefaults.standard.secretObject(forKey: AppConstant.AuthToken) as! String]

阿拉莫法尔法:

Alamofire.request(mobileInfo, method:.put, parameters: params, encoding: JSONEncoding.default, headers: headers).responseJSON { response in

希望这对你有用,祝你好运.. :)

于 2018-09-24T08:00:54.657 回答