Ami*_*r_P 2 xcode swift alamofire
最近我将我的xcode更新到8.0版和Alamofire 4.0.之后我得到Use of undeclared type 'Response'了这段代码:
func getDate(completion: (Response<AnyObject,NSError>) -> Void){
Alamofire.request(.GET, "http://www.example.ir/api/utiliti/example" ,parameters:nil)
.responseJSON{ response in
completion(response)
}
}
Run Code Online (Sandbox Code Playgroud)
我在alamofire github上发布了一个问题并得到了答案!
使用此代码
public enum Response {
case Failed(error : String)
case Success(data : Any)
}
func getDate(completion: @escaping (Response) -> Void){
Alamofire.request("www.example.com/api", method: .get ,parameters:nil)
.responseJSON{ response in
switch response.result{
case .failure(let error):
case .success(let value):
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1780 次 |
| 最近记录: |