[已解决]swift 把函数当作(callback,handler的)参数

写了个函数,带函数的参数的:
func getUrlRespJsonDict_async(url:String, respJsonDictHandler:((JSON?) -> Void)) {
    var decodedJsonDict:JSON?

    let params:Dictionary<String, AnyObject>? = nil


    do {
        let opt = try HTTP.GET(
            url,
            parameters: params,
            requestSerializer: JSONParameterSerializer())

        opt.start { response in
            if let err = response.error {
                print("error: \(err.localizedDescription)")
                return
            }

            print("response.statusCode=\(response.statusCode)")
            print("opt finished: \(response.description)")

            decodedJsonDict = JSON(data: response.data)
            print("decodedJsonDict=\(decodedJsonDict)")

            respJsonDictHandler(decodedJsonDict)
        }
    } catch let httpGetError {
        NSLog("http get url=\(url) with params=\(params) got error= \(httpGetError)")
    }
}
但是之前去调用却不行
但是现在调用又好了:
可以编译通过了:
    func fetchTeamItemList_async() {
        。。。
        getUrlRespJsonDict_async(fullFetchTeamIdListUrl, respJsonDictHandler: teamItemJsonDictHandler)
    }

    func teamItemJsonDictHandler(respJsonDict:JSON?) {
        。。。
    }


发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量