在这种情况下,"方法"对于类型查找是不明确的,Alamofire中的错误

Rav*_*ash 54 swift alamofire

我正在使用Alamofire在swift中进行网络处理并遇到一个奇怪的错误.好像我们不能将Method枚举作为参数传递.
[错误在Method参数上]

在此输入图像描述

private func apiRequest(method: Method, url: String, apiData: [String : AnyObject], completion:(finished: Bool, response: AnyObject?) ->Void) {

    Alamofire.request(method, url, parameters: apiData).responseJSON{ response in
        if let JSON = response.result.value {
            completion(finished: true, response: JSON)
        } else {
            completion(finished: false, response:nil)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

har*_*ngh 87

您必须指定从中查找对象类型的模块.呼叫Alamofire.Method


Sul*_*han 14

可能存在名称冲突.要解决此问题,您可以使用enum(包括模块名称)的限定名称:

private func apiRequest(method: Alamofire.Method, ...
Run Code Online (Sandbox Code Playgroud)


ylg*_*hyh 8

我也遇到过这个问题,因为我已经宣布了一些相同的协议名称:

protocol SomeProtocol {
   static func someTypeMethod()
}

protocol SomeProtocol {
   init(someParameter: Int)
}

protocol SomeProtocol {
   var mustBeSettable: Int { get set }
   var doesNotNeedToBeSettable: Int { get }
}
Run Code Online (Sandbox Code Playgroud)


小智 7

使用“Moya”和桥接 ac 框架时出现此错误冲突,通过隐式添加Moya.Method模块来修复它。

var method: Moya.Method  {
    switch self {
       case .login: return .post
       case .register: return .post
    }
}
Run Code Online (Sandbox Code Playgroud)