gpt4 book ai didi

ios - 上下文闭包类型 Response -> void 需要 1 个 agrument 但 3 个在闭包体中

转载 作者:行者123 更新时间:2023-11-28 08:28:21 27 4
gpt4 key购买 nike

此代码完全适用于我之前在 iOS 8 和 swift 2.0 上的项目。

这是我的代码:

let url=NSURL(string: _resourceURL)!

Alamofire.request(.GET ,url).responseJSON { (request : NSURLRequest?,response: NSHTTPURLResponse?, result: Result<AnyObject> ) -> void in
print(result.value.debugDescription)
}

现在我尝试使用 iOS 9、Swift 3.0、alamofire 4.0.0但抛出以下错误:

Generic type 'Result' specialized with too few type parameters (got 1, but expected 2)
Use of undeclared type 'void'
Contextual closure type 'Response -> Void' expects 1 argument, but 3 were used in closure body

最佳答案

如果您没有需要转换 JSON 的特定对象,并且您乐于通过键访问属性,您可以这样做:

Alamofire.request(.GET, url).responseJSON { response in
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}

关于ios - 上下文闭包类型 Response<AnyObject> -> void 需要 1 个 agrument 但 3 个在闭包体中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39445831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com