使用未声明的类型"响应"错误

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)

Ami*_*r_P 5

我在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)

  • 这不回答这个问题.当您在github上发布问题时,问题神奇地解决了? (2认同)