gpt4 book ai didi

swift - 无法将类型 '(NSURLRequest, HTTPURLResponse?, AnyObject?, NSError?) -> Void' 的值转换为预期的参数类型 '(DataResponse) -> Void'

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

我在 codingforentrepreneurs.com 学习如何制作 iOS 应用

现在我在研究 Alamofire。 Xcode 是 8.3.3

这是错误命令。我不明白错误命令。

Cannot convert value of type '(NSURLRequest, HTTPURLResponse?, AnyObject?, NSError?) -> Void' to expected argument type '(DataResponse) -> Void'

这是 ViewController.swift

import UIKit
import Alamofire

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var rTest = Alamofire.request("http://ec2-52-78-193-10.ap-northeast-2.compute.amazonaws.com", method: .get)
.responseJSON(completionHandler: isComplete)
}

func isComplete(request:NSURLRequest, response: HTTPURLResponse?, data: AnyObject?, error:NSError?) -> Void {
print(response!.statusCode)
print(data)
print(error)
print(request)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

我不知道是什么问题。你能帮帮我吗?

最佳答案

完成处理程序方法的签名应该是这样的。

func isComplete(response: DataResponse<Any>) {
let statusCode = response?.response?.statusCode
let result = response?.result
let request = response?.request
}

关于swift - 无法将类型 '(NSURLRequest, HTTPURLResponse?, AnyObject?, NSError?) -> Void' 的值转换为预期的参数类型 '(DataResponse<Any>) -> Void',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44615701/

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