swift 调用中的额外参数 'completion'
Extra argument 'completion' in call in swift
我对 Swift 语言完全陌生..我已经编写了带有完成块的函数
import Foundation
import Alamofire
struct ConnectionManager {
func callGetMethod(url:NSString , completion:(responseData:AnyObject,errorMessage:NSError)->Void)
{
let urlObj = NSURL(string: url)!
Alamofire.request(.GET, urlObj).responseJSON() {
(_, _, data, error) in
completion( responseData: data!, errorMessage: error!)
println(data)
}
}
}
并从我的 viewcontroller 调用,但我在调用中收到错误 Extra argument compilation 。
var stringurl="http://"
ConnectionManager.callGetMethod(url:stringurl,completion:{(responseData,errorMessage) in
})
请给我提意见 ..
提前致谢
您的通话中有 3 个问题:
- 在你的完成块中你没有包含元组
- 无需包含
url
(第一个参数标签)
- 您将
callGetMethod
声明为成员函数,并且您使用结构名称而不是它的对象来调用它。如果您需要通过结构名称调用它,请将其设置为 static
将实施更改为:
struct ConnectionManager
{
static func callGetMethod(url:NSString , completion:(responseData:AnyObject,errorMessage:NSError)->Void)
{
}
}
您需要将调用更改为:
ConnectionManager.callGetMethod("", completion: { (responseData, errorMessage) -> Void in
})
也是你的问题
我对 Swift 语言完全陌生..我已经编写了带有完成块的函数
import Foundation
import Alamofire
struct ConnectionManager {
func callGetMethod(url:NSString , completion:(responseData:AnyObject,errorMessage:NSError)->Void)
{
let urlObj = NSURL(string: url)!
Alamofire.request(.GET, urlObj).responseJSON() {
(_, _, data, error) in
completion( responseData: data!, errorMessage: error!)
println(data)
}
}
}
并从我的 viewcontroller 调用,但我在调用中收到错误 Extra argument compilation 。
var stringurl="http://"
ConnectionManager.callGetMethod(url:stringurl,completion:{(responseData,errorMessage) in
})
您的通话中有 3 个问题:
- 在你的完成块中你没有包含元组
- 无需包含
url
(第一个参数标签) - 您将
callGetMethod
声明为成员函数,并且您使用结构名称而不是它的对象来调用它。如果您需要通过结构名称调用它,请将其设置为 static
将实施更改为:
struct ConnectionManager
{
static func callGetMethod(url:NSString , completion:(responseData:AnyObject,errorMessage:NSError)->Void)
{
}
}
您需要将调用更改为:
ConnectionManager.callGetMethod("", completion: { (responseData, errorMessage) -> Void in
})
也是你的问题