Cannot call value of non-function type 'NSHTTPURLResponse?'

删除回忆录丶 提交于 2019-12-10 17:32:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!