我已经将AFNetworking 2.5桥接到我的Swift项目中。
我有以下功能:
internal func performAction(var httpMethod: String, var url : String, headers: Dictionary<String, String>?, params: Dictionary<String, AnyObject>?, successClosure: ((operation: AFHTTPRequestOperation, responseObject: AnyObject?) -> ())?, failureClosure: ((operation: AFHTTPRequestOperation, error: NSError) -> ())?) {
let manager = AFHTTPRequestOperationManager()
let internalSuccessClosure = { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) -> Void in
if let succ = successClosure {
succ(operation: operation, responseObject: responseObject)
}
}
let internalFailureClosure = { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in
if let fail = failureClosure {
fail(operation: operation, error: error)
}
}
var methodParams = (url, params, internalSuccessClosure, internalFailureClosure)
if httpMethod == HTTP_METHOD_GET {
manager.GET(methodParams)
} else if httpMethod == HTTP_METHOD_POST {
manager.POST(methodParams)
}
}
Swift编译器抱怨:Missing argument for parameter 'parameters' in call
和manager.GET(methodParams)
manager.POST(methodParams)
以下对manager.GET()的调用按预期编译:
manager.GET(url,
parameters: params,
success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
if let succ = successClosure {
succ(operation: operation, responseObject: responseObject)
}
},
failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
if let fail = failureClosure {
fail(operation: operation, error: error)
}
})
我已经尝试了为多个参数参数传递元组的基本示例,并且它已经有效,所以我不确定为什么我在这里遇到问题。
我在Playground中试过这个,它按预期工作:
func addTwoNumbers(x: Int, y: Int) -> Int {
return x + y
}
let twoNumbers = (1,2)
addTwoNumbers(twoNumbers)
我已检查过:https://medium.com/swift-programming/facets-of-swift-part-4-functions-3cce9d9bba4和How to append a tuple to an array object in Swift code?但他们无法帮我解决问题。
答案 0 :(得分:0)
似乎无法将元组作为参数值传递给objective-c代码。