问题
I've seen this problem a few times on this site but none of the solutions seem to work.
I am extending the alamofire request to have an array of repo objects as a result; however, I keep getting the error in the title. Here is the code:
extension Alamofire.Request {
class func repoArrayResponseSerializer() -> ResponseSerializer<Array<Repo>, NSError> {
return ResponseSerializer { request, response, data, error in
guard error == nil else { return .Failure(error!) }
guard data != nil else { return .Failure(error!) }
do {
let jsonData: AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments)
let json = JSON(jsonData!)
if json.error != nil || json == nil {
return .Failure(error!)
}
var repos: Array = Array<Repo>()
for (_, jsonRepo) in json {
let repo = Repo(json: jsonRepo)
repos.append(repo)
}
return .Success(repos)
} catch {
return .Failure(error as NSError)
}
}
}
func responseRepoArray(completionHandler: Result<Array<Repo>, NSError> -> Void) -> Self {
return response(responseSerializer: Request.repoArrayResponseSerializer(), completionHandler: completionHandler)
}
}
Any and all help is appreciated.
来源:https://stackoverflow.com/questions/36561183/cannot-call-value-of-non-function-type-nshttpurlresponse