Contextual Type for Closure Argument List Expects 1 Argument, But 4 Were Specified

Contextual type for closure argument list expects 1 argument, but 4 were specified

The closure takes a single parameter of type Response<AnyObject, NSError> so your code should look more like this.

Alamofire.request(.POST, urlString, parameters: parameters).responseJSON { response in
let json = JSON(response.data!)
let token = json["token"].string
response(token: token)
}

Contextual type for closure argument list expects 1 argument, but 2 were specified

As I understand, you are trying to to the following:

return (0..<k).map { Cluster(centroid: centroids[$0], size: clusterSizes[$0]) }

From the Swift's Zip2Sequence<Sequence1, Sequence2> documentation:

A sequence of pairs built out of two underlying sequences, where the
elements of the ith pair are the ith elements of each underlying
sequence.

Zip2Sequence<[T], [Int]> generator's element is (T, Int) tuple.
You can access the individual elements of this tuple by their index.

So, the following code should work for you:

return Zip2Sequence(centroids, clusterSizes).map { Cluster(centroid: $0.0, size: $0.1) }

Contextual closure type '() - Text' expects 0 arguments, but 1 was used in closure body

You have two closures, so $0 from first one (even if it would be correct, but with _ in you just ignore it) is not available in second one.

The fix is to use argument explicitly, like

ForEach(1..<18) { index in   // << here !!
NavigationLink(destination: chapterrun()) {
Text("Chapter \(index)") // << here !!
}
}

Contextual closure type 'Response AnyObject, NSError - Void' expects 1 argument, but 4 were used in closure body

just use like this

    Alamofire.request(.POST, Constants.userMarks.url, parameters: Constants.userMarks.params).responseJSON { response in
let json = JSON(response.data!)
let token = json["token"].string
response(token: token)
}

Use single argument

Contextual closure type error when accessing the class file in swift

As Leo Dabus commented, you cannot pass a single argument closure (your closure takes one argument c of type Callback) as a parameter expecting three-argument closure.

This is the effect of SE-0110 Distinguish between single-tuple and multiple-argument function types.
The status of the proposal currently shows as Deferred, but the most functionality of this proposal is already implemented and effective in Swift 4, and only a little part (including Addressing the SE-0110 usability regression in Swift 4) is rewinded and under re-designing.

One possible fix would be something like this:

class TTSHttpRequest {

typealias Callback = (data: Data?, response: URLResponse?, error: Error?)

static func submit(withUrl url: String, andHeaders headers: [String: String]? = nil, andBody body: Data? = nil, _ callback: @escaping (Callback) -> ()) {
guard let url = URL(string: url) else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
headers?.forEach({ (header: (key: String, value: String)) in
request.setValue(header.value, forHTTPHeaderField: header.key)
})
if let body = body {
request.httpBody = body
}
let task = URLSession.shared.dataTask(with: request) { data, response, error in //<- three arguments
callback((data, response, error)) //<- Call the callback with one tuple.

}
task.resume()
}

}

How to fix Contextual closure type '((String, JSON), (String, JSON)) - Bool' expects 2 arguments, but 1 was used in closure body?

In sorted closure changed $0.0.1 with $0.1 to access first closure argument and $0.1.1 with $1.1 to access second closure argument after making this changes you all set to go.

self.arrData = json.sorted{ $0.1["chkincount"].doubleValue > $1.1["chkincount"].doubleValue }.map { $0.1 }


Related Topics



Leave a reply



Submit