如何在Alamofire中快速提出PUT请求4

时间:2019-01-21 12:52:30

标签: swift alamofire

我是swift和Alamofire的新手,我从表视图中发布的服务中获得了数据,但是用户可以选择编辑表视图中显示的数据。编辑的数据应更新服务,并将编辑的新数据发布到表视图。

服务数据:

[
    {
        "Id": 1,
        "Name": "Sr",
        "designation": "",
        "officeLandLine": "456123789",
        "officeMobile": "789456",
        "officeEmail": "klm@mail.com",
        "personalEmail": "",
        "address": ""
    },
    {
        "Id": 2,
        "Name": "S",
        "designation": "D",
        "officeLandLine": "0863",
        "officeMobile": "810",
        "officeEmail": "dy@gov.in",
        "personalEmail": "",
        "address": ""
    },

1 个答案:

答案 0 :(得分:-2)

请尝试以下操作:

func serviceCallForUpdateData(withSelectedIndex index: Int){

    let param = ["id" : self.arry[index].id, "name" : self.arry[index].name]
        let requestURL = "your url"
            print("*****************************  URL: *********************************\(requestURL)")
            Alamofire.request(requestURL, method: .put, parameters: param as? Parameters, encoding: JSONEncoding.default, headers: nil).responseJSON { (responseJson) in
                print("Response : \(responseJson)")
                if (responseJson.result.isSuccess){
                    let dictRes = responseJson.result.value as! NSDictionary
                    completion(["res":dictRes, "stats":1] as AnyObject?)
                } else {
                    let res : NSDictionary = ["msg":"Network Error"]
                    completion(["res":res, "stats":0] as AnyObject?)
                }

            }
}

在表格视图的didSelect方法中调用此函数。

您可以从数组didSelect方法中获取数据。

在dedSelect方法中,请输入:

self.serviceCallForUpdateData(index : indexPath.row)

这可能会对您有所帮助。谢谢