Swift-Alamofire completionhandler
我正在与Alamofire合作从web API检索数据:Swift-Alamofire completionhandler,swift,get,request,alamofire,Swift,Get,Request,Alamofire,我正在与Alamofire合作从web API检索数据: func getData(completionHandler: (responseObject: NSDictionary?) -> ()) -> () { Alamofire.request(.GET, "http://example.com/api/resource/") .validate() .authenticate(user: user, password: password
func getData(completionHandler: (responseObject: NSDictionary?) -> ()) -> () {
Alamofire.request(.GET, "http://example.com/api/resource/")
.validate()
.authenticate(user: user, password: password)
.responseJSON { (request, response, responseObject) in
switch responseObject {
case .Success:
print("Validation Successful")
completionHandler(responseObject: responseObject as? NSDictionary)
case .Failure(_, let error):
print(error)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
getData { (str, error) in
if str != nil {
print(str)
} else {
print(error)
}
}
}
当我运行代码时,它给出了一个错误,错误如下所示
Command failed due to signal: Segmentation fault: 11
我不知道它出了什么问题以及如何修复它。
非常感谢您的任何建议。在使用Alamofire时遇到过类似问题。我删除并重新导入了框架,然后它就工作了。看起来编译器对此有些问题 无论如何,也要尝试清理你的项目
如果仍然不起作用,请尝试设置
断点(或简单地注释)嵌套部分,以确定故障的确切位置。您调用的getData
不正确。您正在向完成处理程序传递两个参数(str,error
,而它只接受一个响应对象