Swift 3.0,Alamofire 4.0调用中的额外参数'method' [英] Swift 3.0, Alamofire 4.0 Extra argument 'method' in call

查看:191
本文介绍了Swift 3.0,Alamofire 4.0调用中的额外参数'method'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关此问题的所有问题。我有以下代码

I have read all the questions on this issue this and this. I have the following code

let fullURL = God.getFullURL(apiURL: self.apiUrl)
        if (getOrPost == God.POST) {
            Alamofire.request(fullURL, method: .POST, AnyObject: self.postData?, encoding:.JSONEncoding.default, headers: nil).responseJSON{ response in
                self.responseData = response.result.value
            }
        } else if (getOrPost == God.GET) {
            Alamofire.request(fullURL, method : .GET, Parameters: getData, encoding:.JSONEncoding.default, headers: nil).responseJSON{ response in
                self.responseData = response.result.value
            }
        }

My Swift和Xcode版本

My Swift and Xcode versions are

Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9
Version 8.2.1 (8C1002)

我的pod文件是

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target 'Buseeta' do
        pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'master'
end

pod 'AlamofireObjectMapper', '~> 4.0'

pod 'SwiftyJSON'

我得到在两个Alamofire请求行的调用错误中的额外参数'method'。

I get Extra argument 'method' in call error on both Alamofire request lines.

不要仔细检查,不要将此问题标记为重复。我已按照重复的问题完全修正了代码。

Dont go mark this question as duplicate without carefully checking. I have fixed the code exactly as per the duplicate questions.

编辑1

我在删除标题后尝试过,同样的问题出现在 .POST .GET

I tried after removing the headers, same issue on .POST and .GET

let fullURL = God.getFullURL(apiURL: self.apiUrl)
        if (getOrPost == God.POST) {
            Alamofire.request(fullURL, method: .POST, AnyObject: self.postData?, encoding:.JSONEncoding.default).responseJSON{ response in
                self.responseData = response.result.value
            }
        } else if (getOrPost == God.GET) {
            Alamofire.request(fullURL, method : .GET, Parameters: getData?, encoding:.JSONEncoding.default).responseJSON{ response in
                self.responseData = response.result.value
            }
        }

编辑2

if (getOrPost == God.POST) {
            Alamofire.request(fullURL, method: .post, parameters: self.postData?, encoding:.JSONEncoding.default).responseJSON{ response in
                self.responseData = response.result.value
            }
        } else if (getOrPost == God.GET) {
            Alamofire.request(fullURL, method : .get, parameters: getData?, encoding:.JSONEncoding.default).responseJSON{ response in
                self.responseData = response.result.value
            }
        }

编辑3

我替换为方法:HTTPMethod.get,仍然没有变化。同样的问题。

I replaced with method : HTTPMethod.get, still no change. Same issue.

推荐答案

您需要使用其他功能上传数据:

You need to use another function to upload data:

func upload(
    _ data: Data,
    to url: URLConvertible,
    method: HTTPMethod = .post,
    headers: HTTPHeaders? = nil)
    -> UploadRequest

GET请求的参数必须是[String:Any]类型

And parameters for GET request must be of type [String: Any]

这篇关于Swift 3.0,Alamofire 4.0调用中的额外参数'method'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆