我对名为APIManager的类有一个扩展名:
import Alamofire
import Foundation
// MARK: - Logout
extension APIManager {
public func performLogout() {
let request = defaultManager.request(APIManager.Router.Logout.URLRequest)
request.response( // ERROR ON THIS LINE AS NOTED BELOW
queue: APIManager.responseQueue,
responseSerializer: Request.stringResponseSerializer(),
completionHandler: { [weak self] (response) in
guard let strongSelf = self else { return }
}
)
}
}
当扩展名包含在相同文件中的APIManager类下面时,没有任何问题。
但是,当我接受扩展并将其移动到新文件时,我收到此错误:
无法调用非函数类型的值'NSHTTPURLResponse?'
很明显,当扩展名放在另一个文件中时,编译器会将上面的方法混淆为Alamofire / ResponseSerialization.swift和Alamofire请求类的Alamofire / Request.swift中的'response'属性
APIManager类如下:
public final class APIManager {
// MARK: - Singleton shared instance
static let sharedInstance = APIManager()
let defaultManager: Alamofire.Manager = {
let serverTrustPolicies: [String: ServerTrustPolicy] = [
"TBD1": .PinCertificates(
certificates: ServerTrustPolicy.certificatesInBundle(),
validateCertificateChain: true,
validateHost: true
),
"TBD2": .DisableEvaluation
]
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
configuration.HTTPAdditionalHeaders = Alamofire.Manager.defaultHTTPHeaders
return Alamofire.Manager(
configuration: configuration,
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
}()
}
这里有一个类似的问题,但它并不完全相同:
Cannot call value of non-function type 'NSHTTPURLResponse?' Alamofire ObjectMapper
答案 0 :(得分:1)
如果是这样,正如你所说,在另一个文件中正常工作会想到一些建议。
如果您的问题仍然存在,请告诉我,我会进一步调查。