Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

ios - Swift 3.0, Alamofire 4.0 Extra argument 'method' in call

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 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)

My pod file is

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'

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.

EDIT 1

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
            }
        }

EDIT 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
            }
        }

EDIT 3

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to use another function to upload data:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...