Swift 3和Alamofire发送方法作为参数

时间:2017-01-26 13:11:26

标签: swift alamofire

我是swift的新手,我遇到了请求问题。我想向函数发送不同的方法,它将返回一个字符串,但我不知道如何做。我试过这种方式,但我得到了

  

错误类型的.post错误并返回函数makeWebServiceCall

有人能帮助我吗?

public func login(userName: String, password: String) -> [String:Any]{

let loginrequest = JsonRequests.loginRequest(userName: userName, password: password)
return makeWebServiceCall(urlAddress: URL, requestMethod: .post, params: loginrequest)

}

private func makeWebServiceCall (urlAddress: String, requestMethod: String, params:[String:Any]  ) -> [String:Any] {

Alamofire.request(urlAddress, method: requestMethod, parameters: params, encoding: JSONEncoding.default).responseJSON { response in

   if let JSON = response.result.value {
        print("JSON: \(JSON)")
    }

编辑:

enter image description here

1 个答案:

答案 0 :(得分:0)

requestMethod类型应为HTTPMethod

private func makeWebServiceCall (urlAddress: String, requestMethod: HTTPMethod, params:[String:Any]  ) -> [String:Any] { ... }
相关问题